Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

PerlTaintCheck and configuration for secure paths

by geektron (Curate)
on Jun 22, 2006 at 17:25 UTC ( #556956=perlquestion: print w/replies, xml ) Need Help??

geektron has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on an application that requires some user-uploaded (image) thumbnail files. Accomplishing that part is simple enough and has already been accomplished.

Now, I'm trying to configure my mod_perl server to allow those directories when PerlTaintCheck is enabled.

I've read through various parts of Practical mod_perl to determine the appopriate settings, but what seemed to be the proper configuration is still warning me of insecure path dependencies ...

I've tried the following in my httpd.conf (within the VirtualHost section):

PerlSetVar RAW_IMAGES /home/httpd/server_root/rawimages PerlSetVar FINAL_IMAGE_DIR /home/httpd/server_root/graphics/uploaded_i +mages PerlSetEnv PATH /home/httpd/server_root/rawimages:/home/httpd/server_r +oot/graphics/uploaded_images PerlTaintCheck On
but i still get: Insecure dependency in open while running with -T switch when I'm trying to write out a thumbnailed image....

Doesn't the PATH setting include filesystem locations that are acceptable for write access?

This is the exact call that fails: open( NEWIMG, "+>$thumbName" ) or croak "Can't open new imagefile: ($thumbName)  $! \n";
I've added a warn() just before the open, and the attempted image name: /home/httpd/server_root/graphics/uploaded_images/679_lg.jpg

that filesystem location is clearly in the PATH setting ... what is it I'm missing?

Replies are listed 'Best First'.
Re: PerlTaintCheck and configuration for secure paths
by shmem (Chancellor) on Jun 22, 2006 at 17:37 UTC
    It's not $PATH, but the variable. $PATH is only relevant for executables (used with system, backticks or piped open).

    Did you sanitize $thumbName? see perlsec, section Laundering and Detecting Tainted Data.

    Try something like

    $thumbName = ($thumbName =~ /^([-\@\w.\/]+)$/) ? $1 : undef; if($thumbName) { open( NEWIMG, "+>$thumbName" ) or croak "Can't open new imagefile: + ($thumbName) $! \n"; }
    That should do.
    _($_=" "x(1<<5)."?\n".q/)Oo.  G\        /
                                  /\_/(q    /
    ----------------------------  \__(m.====.(_("always off the crowd"))."
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      $thumbName is constructed in the code. because of that, i thought it didn't need extra sanitizing.

      I'll test it w/ Scalar::Util to ensure that's the tainted part ...

        If $thumbName was constructed with whatsoever variable that is tainted and not sanitized, it becomes tainted as well.

        In perlsec is a snippet of code:

        sub is_tainted { return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 }; }
        _($_=" "x(1<<5)."?\n".q/)Oo.  G\        /
                                      /\_/(q    /
        ----------------------------  \__(m.====.(_("always off the crowd"))."
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://556956]
Approved by Hue-Bond
Front-paged by Hue-Bond
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: (3)
As of 2019-05-26 01:59 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (152 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!