Solved

CFFILE and Tif Files

Posted on 2001-08-09
11
485 Views
Last Modified: 2013-12-24
When I upload a TIF file via CFFILE I am informed that the mime type for this file is "Application/Octet-stream" rather than "images/tiff".  

This allows users to upload executables which is obviously a security risk.  We don't want this to happen.

Is there a solution to this problem ?

I would be grateful for all advice offered.

Thanks in advance

John
0
Comment
Question by:johnclarke
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
detect the type of file it was and delete it if it isn't type tiff...

<CFSET uploadPath = "d:\inetpub\wwwroot\mywebsite\uploaddir\">
<CFLOCK timeout="60" throwontimeout="yes">
<cffile action="UPLOAD" filefield="#FORM.filename#" destination="#uploadPath#" nameconflict="MAKEUNIQUE" accept="application/octet-stream">
</CFLOCK>
<CFIF FILE.FileWasSaved>
   <CFIF File.ClientFileExt IS NOT "tiff">
       <CFLOCK timeout="60" throwontimeout="yes">
         <cffile action="DELETE" filefield="#FORM.filename#" destination="#uploadPath#">
       </CFLOCK>      
       Please upload TIFF Files only.
       File was not uploaded
   </CFIF>
</CFIF>

You can use JavaScript to check the extension before they click submit.

You can also do some parsing of the name to check the extension before you upload.

CJ
0
 

Author Comment

by:johnclarke
Comment Utility
CJ,
   Thanks for your comment.  In the program we need to upload more than one type of file.  However, we wish to prevent a user from upload executables (eg PL,EXE, etc).

Users can change the file extension so we need a way to make CFFILE identify the correct mime type.

Thanks in advance

John
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
Well, the problem is that the mime-type of a file is dictated by the browser settings.. so I can change go and change my browser settings to make .exe files of type image or whatever.

CJ
0
 
LVL 14

Expert Comment

by:SBennett
Comment Utility
The best way to do this would be to have a javascript validation on the form and to also set the <cffile> tag to only accept the MIME type you want. The following example is set to accept gif's, bmp's, jpg's, and tif's.

NOTE: CJ had the same answer as this so If it works for you he should get the points. I just decided to give you some example code to look at since I had it handy.

-Scott





ImageUpload_1.cfm:

----------------------------------------------------------

<!--- This Javascript Validates the Image field --->
<script language="JavaScript1.2">

   
function Check_File_Field(){

         var TheValue = eval("document.ImageUpload.ImageFile.value");
         var FileType = TheValue.substr(TheValue.length-3, 3);
         
         if (TheValue == ""){
              alert("Please Select an Image to Upload");
         }
         
         
         if ( FileType == "gif" || FileType == "jpg" || FileType == "bmp" || FileType == "tif" ) {
                   document.ImageUpload.submit();
         }
         
         else{
              alert("The file is not a valid Image file.");
              eval("document.ImageUpload.ImageFile.focus()");
         }
    }
</script>
ImageUpload_1.cfm:

<!--- This form uploads the Image --->
<cfform name="ImageUpload" action="ImageUpload_2.cfm" enctype="multipart/form-data">
<input name="ImageFile" type="file">
<input type="Button" value="Upload Image" onclick="Check_File_Field()">
</cfform>

----------------------------------------------------------

ImageUpload_2.cfm:

-----------------------------------------------------------

<!--- If a file has been uploaded use cffile to check that it is am image file and store it in your
image folder --->
<cfif isDefined("Form.ImageFile")>
<CFFILE ACTION="upload"
   FILEFIELD="ImageFile"
   DESTINATION="C:\inetpub\wwwroot\ImageFolder"     NAMECONFLICT="MakeUnique"
    Accept="image/gif, image/pjpeg, image/bmp, image/tif"
    >

<!--- The following structure contains info on the file wich may be helpful for you to add the image
to your content management system --->

<cfset stFile = StructNew()>
<cfset stFile.FileName = "#file.serverfile#">
<cfset stFile.FilePath = "#file.serverdirectory#">
<cfset stFile.FileURL = "/ImageFolder/#file.serverfile#">

</cfif>

---------------------------------------------------------



0
 
LVL 5

Expert Comment

by:heathprovost
Comment Utility
"Users can change the file extension so we need a way to make CFFILE identify the correct mime type."

The mime type is entirely determined by the file extension anyway, so it really wont matter much.

Heath
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 1

Accepted Solution

by:
snakehollywood earned 50 total points
Comment Utility
To check a whole bunch of extensions from CF use

<CFIF NOT ListFind(File.ClientFileExt, "tiff,jpg,gif")>
delete the file
</cfif>
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
johnclarke--->  You logged in recently, but did not update/finalize your open questions.  Please do.

If you've been helped, please accept the expert comment which helped you to grade and close it.  If you need help splitting points between multiple experts, comment with detail.

I will post this in all your open questions and monitor them for closure.  Please check the HELP DESK link on the left for site-related information on the Question/Answer process, Guidelines and Member Agreement.

Expert input is always welcome to determine the fair outcome of this question in the event johnclarke does not respond.

Thanks all,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
IMHO split btw SBennett and me.

CJ
0
 
LVL 14

Expert Comment

by:SBennett
Comment Utility
I find it odd that snakehollywood's comment was accepted as the answer for this question. In my opinion it was probably the least usefull comment on this whole string.

Scott
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
Well, I guess if it satisfied the question asker...

CJ
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
Thanks, johnclarke, for returning and updating/finalizing your questions.  Thank you also, CJ.

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now