How can I determine the actual types of files uploaded by the browser?

Source: Internet
Author: User
For example, how do you know if a user uploads an image? Obviously, the suffix name is not reliable, and the mime information in the form is most likely to be forged is not reliable. How can I determine the type of all the form information? Do I need to parse this binary file? For example, how do you know if a user uploads an image?

  1. The suffix is obviously unreliable and the easiest to forge
  2. The mime information in the form is not reliable, and all form information can be forged.

How can I determine its type? Do I need to parse this binary file?

Reply content:

For example, how do you know if a user uploads an image?

  1. The suffix is obviously unreliable and the easiest to forge
  2. The mime information in the form is not reliable, and all form information can be forged.

How can I determine its type? Do I need to parse this binary file?

There is no other way to parse binary files. Even parsing binary files may also be cheated. PDF files that can be used to jailbreak the iPhone have existed.

There are many things you can't do absolutely. In a single sentence, you can do everything you need.

For imagesgetimagesize()Obtain the imagemimeIn this way, it does not depend on
Common files can be accessed through:
1.Finfo Extension
2.mime_content_type()
3. Call linux commandsexec("file -bi ".escapeshellarg($this->file_src_pathname))To detect
It is sufficient to select an appropriate detection document type.
The security of image uploading is mainly used when downloading and displaying images. If it is a script《script》alert(1)《script》Forgedimage/jpg, The browser will interpret it as html rather than an image to execute an invalid script. The above detection methods can avoid this situation

The simplest and safer method is to verify the signature information of the file.

PHP reference: http://www.codecto.com/article/4.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.