Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Security issues when allowing file upload via CGI

by Fastolfe (Vicar)
on Dec 06, 2001 at 20:50 UTC ( #129985=note: print w/ replies, xml ) Need Help??


in reply to Security issues when allowing file upload via CGI

With a pre-defined list of acceptable file types, you can ensure that the file extension is what you expect, but even that isn't enough, as MSIE frequently second-guesses the web server-provided MIME type. A more thorough solution would be for you to use something like File::MMagic to ensure the contents are of a pre-defined acceptable MIME type as well.

Unfortunately, short of installing a virus scanner in line with this process, or on a system constantly scanning new uploads for known viruses, there is no easy way for you to catch every conceivable piece of malicious data. Even explicitly allowing, say, JPEG images only, can still open you up to some vulnerabilities with carefully crafted JPEG code.

Another caveat is getting the file someplace "local" to that user. Be wary of using user-provided variables to determine the location on a filesystem a file should reside. See Sanitizing user-provided path/filenames if this is the case here.

I might also use umask instead of explicitly calling chmod to make changes to the permissions of the file.

And lastly since this feature of your site inevitably opens you up to the potential for scripting vulnerabilities (users uploading data with HTML and/or JavaScript that will be executed in the context of your own site), you should be careful with the nature of the cookies you send to the user to avoid potentially sharing this with evil-doers. You should make sure nobody else can steal someone's cookie and pass it off as one of their own, for instance.


Comment on Re: Security issues when allowing file upload via CGI

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://129985]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-08-20 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (113 votes), past polls