G'day Bod,

I didn't see it mentioned anywhere in the thread, so I thought I'd point out a general problem that you could be experiencing.

Here's a taint_test module:

$ cat taint_test.pm package taint_test; use strict; use warnings; chdir +(split /:/, $ENV{PATH})[0];

Here's a script that tries to clean $ENV{PATH}:

$ cat check_taint_1.pl use strict; use warnings; $ENV{PATH} = '/bin:/usr/bin'; use lib '.'; use taint_test;

But that fails:

$ perl -T check_taint_1.pl Insecure dependency in chdir while running with -T switch at taint_tes +t.pm line 6. Compilation failed in require at check_taint_1.pl line 6. BEGIN failed--compilation aborted at check_taint_1.pl line 6. $

The problem here is that the assignment to $ENV{PATH} occurs at runtime, whereas loading taint_test occurs at compile time. The order of the statements makes no difference: compile time happens before runtime.

Here's a subtly different version of the first script:

$ cat check_taint_2.pl use strict; use warnings; BEGIN { $ENV{PATH} = '/bin:/usr/bin'; } use lib '.'; use taint_test;

And this one works:

$ perl -T check_taint_2.pl $

Both assignment and loading occur at compile time; the order of the statements now matters.

Here's a third version of the script with the order of statements changed:

$ cat check_taint_3.pl use strict; use warnings; use lib '.'; use taint_test; BEGIN { $ENV{PATH} = '/bin:/usr/bin'; }

And, as expected, this fails:

$ perl -T check_taint_3.pl Insecure dependency in chdir while running with -T switch at taint_tes +t.pm line 6. Compilation failed in require at check_taint_3.pl line 5. BEGIN failed--compilation aborted at check_taint_3.pl line 5. $

Bear this in mind for things other than untainting $ENV{PATH}.

— Ken


In reply to Re: Insecure CPAN module in taint mode by kcott
in thread Insecure CPAN module in taint mode by Bod

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.