logo       

Re: Download images/movies: msg#00074

Subject: Re: Download images/movies
>Perhaps set the path of the image directory
>into the script, hardcoded like so:
>
>   $path = '/home/fubar/www/images';
>
>or something like that so you are restricting to a certain directory,
>and not just letting any file be read in by the cgi and sent to the

This isn't safe either. Someone could come along and request:

 http://site.com/server.cgi?file=../../../../../../../etc/passwd

and get naughty files too. You want to make sure that you always
sanitize the filename that you get in - never trust it. You also
want to think about this /the other way/ - instead of thinking
"what should I filter out?", you should think "what is it that
I want to accept?". In your case, you'd probably only want
alphanumeric characters only, and a single dot (to separate
the file extension).

I've done stuff similar to:

 my $images = '/home/fubar/www/images';   # where your files live.
 my $incoming = $cgi->param('file');      # the file the user wants.
 my $file_path = File::Spec->catfile($images, $incoming);

 my ($v, $directories, $f) = File::Spec->splitpath($file_path);
 my @path_parts = File::Spec->splitdir($directories);
 push(@path_parts, $f); # check the file for naughties too.
 return $self->error("Hi! You've attempted directory traversal. Naughty!")
     if scalar File::Spec->no_upwards(@path_parts) != scalar @path_parts;

The above just checks for ".." and equivalents, however. You will
probably want to check your $incoming for naughty characters too,
just to be safe (ie., anything not a dot or an alphanumeric).


--
Morbus Iff ( you are nothing without your robot car, NOTHING! )
Culture: http://www.disobey.com/ and http://www.gamegrene.com/
Spidering Hacks: http://amazon.com/exec/obidos/ASIN/0596005776/disobeycom
icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe