Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:38:35+00:00 2026-05-26T20:38:35+00:00

Background In a targeted issue tracking application (in django) users are able add file

  • 0

Background

In a targeted issue tracking application (in django) users are able add file attachments to internal messages. Files are mainly different image formats, office documents and spreadsheets (microsoft or open office), PDFs and PSDs.

A custom file field type (type extending FileField) currently validates that the files don’t exceed a given size and that the file’s content_type is in a the applications MIME Type ‘white list’. But as the user base is very varied (multi national and multi platform) we are frequently having to adjust our white list as users using old or brand new application versions have different MIME types (even though they are valid files, and are opened correctly by other users within the business).

Note: Files are not ‘executed’ by apache, they are just stored (with unix permissions 600) and can be downloaded by users.

Question

What are the pro’s and con’s for the different types of validation?

A few options:

  • MIME type white list or black list
  • File extension while list or black list
  • Django file upload input validation and security even suggests “you have to actually read the file to be sure it’s a JPEG, not an .EXE” (is that even viable when numerous types of files are to be accepeted?)

Is there a ‘right’ way to validate file uploads?

Edit

Let me clarify. I can understand that actually checking the entire file in the program that it should be opened with to ensure it works and isn’t broken would be the only way to fully confirm that the file is what it says it is, and that it isn’t corrupted.

But the files in question are like email attachments. we can’t possibly verify that every PSD is a valid and working Photoshop image, same goes for JPG or any other type. Even if it is what it says it is, we couldn’t guarantee that it’s a fully functional file.

So What I was hoping to get at is: Is file magic absolutely crucial? What protection does it really add? And again does a MIME type whitelist actually add any protection that a file extension whitelist doesn’t? If a file has an file extension of CSV, JPG, GIF, DOC, PSD is it really viable to check that it is what it says it is, even though the application itself doesn’t depend on file?

Is it dangerous to use simple file extension whitelist excluding the obvious offenders (EXE, BAT, etc.) and, I think, disallowing files that are dangerous to the users?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:38:36+00:00Added an answer on May 26, 2026 at 8:38 pm

    The best way to validate that a file is what it says it is by using magic.

    Er, that is, magic. Files can be identified by the first few bytes of their content. It’s generally more accurate than extensions or mime types, since you’re judging what a file is by what it contains rather than what the browser or user claimed it to be.

    There’s an article on FileMagic on the Python wiki

    You might also look into using the python-magic package

    Note that you don’t need to get the entire file before using magic to determine what it is. You can read the first chunk of the file and send those bytes to be identified by file magic.

    Clarification

    Just to point out that using magic to identify a file really just means reading the first small chunk of a file. It’s definitely more overhead then just checking the extension but not too mch work. All that file magic does is check that the file “looks” like it’s the file you want. It’s like checking the file extension only you’re looking at the first few chars of the content instead of the last few chars of the filename. It’s harder to spoof than just changing the filename. I’d recommend against a mime type whitelist. A file extension whitelist should work fine for your needs, just make sure that you include all possible extensions. Otherwise a perfectly valid file might be rejected just because it ends with .jpeg instead of .jpg.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: Some time ago, I built a system for recording and categorizing application crashes
I am about to release a free iphone application that is targeted for all
Background I first wanted to upload a file via json and get a response
Background: I am trying to add data to a SQL DB with C#. I
Background I have a secured folder containing secret report files (in pdf format). Each
Background Developing a simple web application (Eclipse + JBoss + Apache Tomcat) to generate
Background Given that 'most' developers are Business application developers, the features of our favorite
Background: I've inherited a web application that is intended to create on-the-fly connections between
Background/context for this question: I have a WPF desktop application. It uses LINQ to
Background: I have a little video playing app with a UI inspired by the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.