Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
On first glance, probably. On the other hand, are you willing to take the chance? Who knows what shell metacharacters may be used in the future? I'd rather deny everything I don't explicitly allow than allow everything I don't explicitly deny.

On the other hand, I would say it's fairly unlikely you'll have a query string AND posted data at the same time, for a normal operation. So it may be a moot point, as I don't expect this script to work very well.

I would recommend you read perlsec and enable Taint mode. Also enable warnings with perl -w and use the strict module. You should also use CGI for your form handling (see my home node or Ovid's CGI course for details).

If you want to be more paranoid, I would build up a hash of *allowed* files, then check the input against them:

my %files = ( '/var/www/index.html' => 1, '/var/www/home/index.html' => 1; ); my $request = $query->param('fulltxtpath'); if (exists($files{$request})) { open (FILE, "> " . $request) or dienice("couldn't open $request: $ +!"); # open and print file } else { # error }
Better yet, use opendir and readdir to build a list of allowed files. You might even use the keys of the hash as their values, and use $files{$request} in the open statement.

Finally, I'd replace the looping substitutions with a transliteration:

$var1 =~ tr/a-zA-Z0-9\/\.\-_//dc;

That's reasonably strict.


In reply to Re: Is this safe?? by chromatic
in thread Is this safe?? by SilverB1rd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-11-28 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?