Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: request for review: file reading security

by Zed_Lopez (Chaplain)
on Sep 05, 2004 at 09:37 UTC ( [id://388588]=note: print w/replies, xml ) Need Help??


in reply to request for review: file reading security

Yeah. As written, the user could pass, e.g., ../topsecretpages/index.html and start looking at the topsecretpages directory that exists at the same level as pages. (Of course, the user would have to guess or learn the name of the directory, and it is to be hoped you don't really have top secret pages lying around under your web server's document root without any protection.)

Updated: Like the followups say, the regexp dealt with that. Teach me to answer SoPWs in the middle of the night...

Replies are listed 'Best First'.
Re^2: request for review: file reading security
by Anonymous Monk on Sep 05, 2004 at 14:33 UTC
    that's why there is $req =~ s/^.*\///; which should take care of that.

      I believe your code should look for literal periods:

      $req =~ s/^\.\.\///;
      But that's still poor, because what about:
      blah/../../topsecretpages/page.html
      or
      ../../topsecretpages/page.html
      Update: Chady is right. I retract.



      pbeckingham - typist, perishable vertebrate.

        His regular expression does the job well. It strips everything until the last /

        $req = 'blah/../../topsecretpages/page.html'; $req =~ s/^.*\///; print $req; __END__ page.html

        He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
        Chady | http://chady.net/
        Are you a Linux user in Lebanon? join the Lebanese Linux User Group.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-25 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found