ColdFusion CFFILE to limit text file upload -
i'm want use cffile upload detect .txt file. i've tried use file.clientfileext detect extension. when txt detected, i'm showing pop error message users , delete file. told should not allow user's file reach our server.
then use cffile accept attribute accept text/plain. should unfortunately on test when tried uploading non text file got coldfusion error:
the mime type of uploaded file application/pdf not accepted server. files of type text/plain can uploaded. verify uploading file of appropriate type.
i tried use cftry , cfcatch still same error, due mime type don't know when file being uploaded browser. found same question in forum , tried suggested answer, did not work, still got same error message (see below)
i found posting in forum not suggest use of cf "accept" attribute. link provided further detail explanation: http://www.petefreitag.com/item/701.cfm
so question is, since i'm still using cf8, don't have many options prevent users uploading other .txt file securely? if can't use accept attribute of cffile, can @ least secure file upload functionality doing following? doing way safe enough?
- upload file temp folder not under root dir
- verify file extension
- change file name if extension detected .txt
- move file destination file under root dir
even if these steps, have allowed file reach our server, order not allow file reach our server.
below answer/suggestion previous question. doesn't work when tested it:
<cftry> <cflock name="write_lock" type="exclusive" timeout="120"> <cffile action="upload" filefield="filepath" destination="#destdir#" nameconflict="overwrite" attributes="archive"> </cflock> <cfcatch> <cfif findnocase("not accepted", cfcatch.message)> <script> $(function(){ alert("only following file types allowed: .jpg, .gif, .bmp, .png."); }); </script> <cfabort /> <cfelse> <!--- looks non-mime error, handle separately ---> <cfdump var="#cfcatch#" abort /> </cfif> </cfcatch> </cftry>
i think steps reasonable if don't using accept
attribute validation. fyi can set accept .txt
instead of mime types. mime type determined client it's safer check extension anyway.
the exception thrown cffile failing attribute validation may not have type
, code posted tried detect findnocase()
looking @ exception's message
. can dump exception out , find out why findnocase()
failed catch exception.
make sure treat whatever uploaded potentially malicious , not process them (e.g. cfinclude them). forcing file extension .txt should safe enough, i'll let other security experts charm in.
Comments
Post a Comment