Skip to content

Instantly share code, notes, and snippets.

@ivanionut
Forked from JamoCA/ScopeInjectionProtection.cfm
Last active August 29, 2015 14:16
Show Gist options
  • Save ivanionut/7c3b0339a6020470b7e6 to your computer and use it in GitHub Desktop.
Save ivanionut/7c3b0339a6020470b7e6 to your computer and use it in GitHub Desktop.
Sample ColdFusion 9+ script to prevent Fallback Scope Injection. URL & Form variables are universally accessible in the scope & used as fallback.
<!--- Sample ColdFusion 9+ script to prevent Fallback Scope Injection. URL & Form variables are universally accessible in the scope & used as fallback.
Based on insights provided by Peter Freitag's blog post http://www.petefreitag.com/item/834.cfm --->
<cfscript>
Scopes = "arguments,local,thread,variables,cgi,cookie,client,request,application,session,server,caller,thistag,this";
for (thisField in Form) {
if (ListLen(thisField,".") GT 1 AND ListFindNocase(Scopes, trim(ListFirst(ThisField,".")))){
StructDelete(Form, thisField);
if (ListFindnocase(Form.Fieldnames, ThisField)){
Form.Fieldnames = ListDeleteAt(Form.Fieldnames, ListFindnocase(Form.Fieldnames, ThisField));
}
}
}
for (thisField in URL) {
if (ListLen(thisField,".") GT 1 AND ListFindNocase(Scopes, trim(ListFirst(ThisField,".")))){
StructDelete(URL, thisField);
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment