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 478835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:43:54+00:00 2026-05-13T00:43:54+00:00

A Django app that I am working has an Event model. An Event may

  • 0

A Django app that I am working has an Event model. An Event may have associated photos, static html files and pdf files.

I would like to allow trusted users to upload these files, but I am wary about security, especially having read the following in the Django docs (link).

Note that whenever you deal with
uploaded files, you should pay close
attention to where you’re uploading
them and what type of files they are,
to avoid security holes. Validate all
uploaded files so that you’re sure the
files are what you think they are. For
example, if you blindly let somebody
upload files, without validation, to a
directory that’s within your Web
server’s document root, then somebody
could upload a CGI or PHP script and
execute that script by visiting its
URL on your site. Don’t allow that.

How can I validate the different types of files? I would be interested to hear anyone’s experience of dealing with this kind of thing, or links for further reading. I have a gut feeling that html files may be too risky, in which case I’ll restrict upload permissions to the administrator.

  • 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-13T00:43:54+00:00Added an answer on May 13, 2026 at 12:43 am

    All the answers are focusing on validating files. This is pretty much impossible.

    The Django devs aren’t asking you to validate whether files can be executed as cgi files. They are just telling you not to put them in a place where they will be executed.

    You should put all Django stuff in a specially Django directory. That Django code directory should not contain static content. Don’t put user files in the Django source repository.

    If you are using Apache2, check out the basic cgi tutorial: http://httpd.apache.org/docs/2.0/howto/cgi.html

    Apache2 might be setup to run any files in the ScriptAlias folder. Don’t put user files in the /cgi-bin/ or /usr/local/apache2/cgi-bin/ folders.

    Apache2 might be set to server cgi files, depending on the AddHandler cgi-script settings. Don’t let the users submit files with extensions like .cgi or .pl.

    However, you do need to sanitize user submitted files so they are safe to run on other clients’ machines. Submitted HTML is unsafe to other users. It won’t hurt your server. Your server will just spit it back at whoever requests it. Get a HTML sanitizer.

    Also, SVG may be unsafe. It’s had bugs in the past. SVG is an XML document with javascript in it, so it can be malicious.

    PDF is … tricky. You could convert it to an image (if you really had to), or provide an image preview (and let users download at their own risk), but it would be a pain for people trying to use it.

    Consider a white-list of files that are OK. A virus embedded in a gif, jpeg or png file will just look like a corrupt picture (or fail to display). If you want to be paranoid, convert them all to a standard format using PIL (hey, you could also check sizes). Sanitized HTML should be OK (stripping out script tags isn’t rocket science). If the sanitization is sucking cycles (or you’re just cautious), you could put it on a separate server, I guess.

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

Sidebar

Related Questions

I have written a Django app that makes use of Python threading to create
I'm using Google App Engine and Django templates. I have a table that I
I am building a simple Django app that will use scribd to display documents.
Is there a good Django app out there that can take a list of
I'm preparing to deploy my Django app and I noticed that when I change
My Django app has a Person table, which contains the following text in a
For my Django app I have Events, Ratings, and Users. Ratings are related to
I have configured my Django app to run under Apache+FastCGI on Linux (Ubuntu, if
I'm developing a Django app, and I'm trying to use Python's logging module for
I'm running a Django app using FastCGI and lighttpd. Can somebody explain me what

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.