Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

CFFILE and Tif Files

Posted on 2001-08-09
11
Medium Priority
?
493 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
ID: 6368141
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
ID: 6368428
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
ID: 6368464
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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 14

Expert Comment

by:Scott Bennett
ID: 6369220
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
ID: 6394577
"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
 
LVL 1

Accepted Solution

by:
snakehollywood earned 200 total points
ID: 6402150
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
ID: 6777997
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
ID: 6779274
IMHO split btw SBennett and me.

CJ
0
 
LVL 14

Expert Comment

by:Scott Bennett
ID: 6780469
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
ID: 6780471
Well, I guess if it satisfied the question asker...

CJ
0
 
LVL 1

Expert Comment

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

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month20 days, 18 hours left to enroll

810 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