• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cffileupload mime type restriction?

New Here ,
Jul 02, 2013 Jul 02, 2013

Copy link to clipboard

Copied

Hello,

I'm trying to implement the cffileupload widget and restrict it to only be able to upload image files

you do have an extension filter which can be set to *.jpg, *.png etc.. but the user can still select other file types by using the *.* command in the explorer popup

so i tought to restrict it on the actual cffile "upload" tag in the backend, however all files are having the mime type "application/octet-stream" and not image/jpg ..

any idea's how to really restrict this tag?

maybe it is related to this issue

http://www.elliottsprehn.com/cfbugs/bugs/81254

tx

Views

659

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jul 02, 2013 Jul 02, 2013

You need to check the cffile.ServerFileExt variable which contains the file extension to make sure it matches your set of allowed extensions. Make sure you upload into a folder outside of the webroot first (such as getTempDirectory()) to avoid some potential security issues.

You can also use IsImageFile() in addition to the file extension test, but you should not rely on isImageFile (always check the file extensions).

If you have CF10 you can use <cffile accept="*.jpg,*.png" strict="false" ...>  a

...

Votes

Translate

Translate
Enthusiast ,
Jul 02, 2013 Jul 02, 2013

Copy link to clipboard

Copied

LATEST

You need to check the cffile.ServerFileExt variable which contains the file extension to make sure it matches your set of allowed extensions. Make sure you upload into a folder outside of the webroot first (such as getTempDirectory()) to avoid some potential security issues.

You can also use IsImageFile() in addition to the file extension test, but you should not rely on isImageFile (always check the file extensions).

If you have CF10 you can use <cffile accept="*.jpg,*.png" strict="false" ...>  as well.

In short - don't rely on the mime type for anything it can be spoofed by a hacker to upload malicious files, always check the file extension (worth repeating).

-- Pete Freitag

Foundeo Inc - Makers of HackMyCF & FuseGuard

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation