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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay