Subsribe to our RSS

latest reactions

Tjarko
I would'nt use cfhtmlhead for anything ; …
Sebastiaan
Hi Tjarko,Would you suggest injecting…
Donald Boer
I tried it but don't get Country and Nam …
Tjarko
hi Mike,My bad.. the following should…
Mike Appenzellar
I tried this and got "Local variabl …

Use OpenDNS

mxna feeds

Topic Voting Opens to Public!CF9 EXIF Removal bugDiscrepancies in the way ColdFusion validates dates.ColdFusion Job Opportunity in Quantico, VAColdFusion Product Manager Speaks About the Rebirth of the PlatformRepeat - ColdFusion 9 does NOT remove the need to var scope!ColdFusion 9 on VirtualBoxWho's on the CFMeetup this week, Thurs Feb 11J2EE Session Cookies on ColdFusion / JRunNotes on Flash Player stability & the futureColdFusion Job Opportunity in Quincy, MAColdFusion Job Opportunity in Miami, FLColdFusion Job Opportunity in Washington, DCColdFusion Job Opportunity in Seattle, WAColdFusion Job Opportunity in Fort Worth, TX

All files are strictly confidential: all information is classified.
© Copyright 2002 - 2010 mximize.com.
All right reserved.

MXNA webfeed

Visit Carlos GallupaPowered by ColdFusion MX

Simple file upload protection

These days it's all over the news that there is a new security bug in ColdFusion regarding file uploads and spoofing the mimetype. We use the bit of code below to simply check for the combination contenttype / extension. If the combination does not match... bye bye

<cfset stAllow = structNew() />
<cfset stAllow["image"] = "jpg,gif,png,jpeg" />
<cfset stAllow["file"] = "doc,xls,pdf,rtf,txt" />
<cfset stAllow["application"] = "zip,rar,doc,pdf,xls,ppt,swf,flv,txt" />
<cfset stAllow["audio"] = "mp3,mpa,mpg,ra,wav" />
<cfset stAllow["video"] = "mov,qt,mpeg,mp3,mpa,mpg" />
<cfset stAllow["text"] = "txt,htm,html,log,css" />

<cfif structKeyExists(stAllow, file.contenttype) && listFindNoCase(stAllow[file.contenttype],file.serverfileext)>
    You may pass...
<cfelse>
    You will NOT pass!!!
    <!--- Delete the file or something --->
</cfif>


This works in a simple yet very effective way. People could still upload a file that is a .cfm and rename it to .gif but for the webserver it will be an image file.. no harm there. You can change the structure to your liking offcourse.

Some other tips are to only set "read" rights to the upload dir, place an application.cfm file with a <cfabort> tag in the upload dir (if it's accessible from the web)

2243 viewed | 2 opinion(s)  | del.icio.us | Digg it | Tjarko @ 07/07/09 12:27 cet


Reactions:

dave wrote.... (mail)

"only set "read" rights to the upload dir,"
then how you gunna upload into it?

07 July 2009 16:42 cet  

Tjarko wrote.... (site)

@dave, read rights for the webserver, not for the filesystem

07 July 2009 16:44 cet  

Leave your comment

Your name


Your url/website/link/email....


Some room for your reaction is placed here..



The answer to the ultimate question is?? (42 ;-))




URL en mail addresses are translated for you... life sometimes is that simple!!