Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Re: Re: Vetting a CGI script

by iburrell (Chaplain)
on Nov 13, 2003 at 19:47 UTC ( [id://306909]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Vetting a CGI script
in thread Vetting a CGI script

Definitely use CGI.pm when doing file uploads. It handles all the details.

It also writes the uploads to temp files. Since these are randomly named and placed in a temporary directory, these won't overwrite anything important. CGI.pm also takes care of removing the temp files once the script is done. With '-private_tempfiles', the file is deleted right after it is created so that nobody else can read. Only the process with the open filehandle can read it.

CGI.pm also imposes size limits on uploads. This makes it harder for attackers to fill up the disk or slow down the network connection.

The next thing to consider is what happens with the uploaded file. Usually it gets copied someplace. It is important that the destination be controlled by the script and not by the uploaded file name. It is a good idea to hard code the destination directory. It should be separate from any script directories. It is also a good idea to keep the uploads separate from the static files. If the filename included with the upload is going to be used, it must be sanitized to remove dangerous characters and any path components.

Finally, most uploads should only be allowed to authenticated users. Allowing uploads from anonymous users is usually a bad idea.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-29 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found