DEV Community

James Moberg
James Moberg

Posted on

1

ColdFusion CGI Scope is not Read-Only

I've was been always under the impression that the ColdFusion CGI scope was "read-only". Apparently, it's not... unless you use Lucee CFML.

I read about a developer in the Adobe Support Community having issues migrating their CF2016 application to CF2021 as the CGI scope was empty. This gave me some cause for concern as that's the same upgrade path that we're taking.

Their application passed the CGI scope to a UDF to sanitize certain keys and the global CGI scope was being cleared when using structClear on the local-scoped variable structClear(local.copyofCGIScope).

Now I've got to go through my codebase and ensure that we aren't accidentally modifying CGI anywhere. :(

<!--- 20220204
This is a test to see if the CGI scope can be cleared.
(I thought that the CGI scope was "read-only".)
Adobe ColdFusion allows it to be cleared by reference.
Lucee throws a "can't clear struct, struct is readonly" error.
GIST: https://gist.github.com/JamoCA/5ebc08505eeb3edfbd54ebdaadc11b8f
CFBUG: https://tracker.adobe.com/#/view/CF-4212734
THREAD: https://community.adobe.com/t5/coldfusion-discussions/cgi-scope-is-empty-with-coldfusion-2021-on-windows-2019/td-p/12634405
TRYCF: Unable to test on TryCF.com or CFFiddle as CGI scope is disabled.
BUGTRACKER: https://tracker.adobe.com/#/view/CF-4212734
NOTE: If you test this, you will need to restart the ColdFusion service or the CGI struct will continue to be
non-existent when dumped as a whole, but all vars still exist and return the correct.
--->
<cfdump var="#cgi#" expand="false" label="CGI (pre-clear)">
<cfscript>
function doStuff(struct sourceStruct){
local.s = arguments.sourceStruct;
structClear(local.s);
}
</cfscript>
<cfset doStuff(cgi)>
<cfdump var="#cgi#" label="CGI (post-clear)">

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay