On a lark I took a quick trip out to CPAN - here's my suggestion written down as probably-useable code (meaning I didn't test it). It installs a filter on the STDOUT filehandle before script execution so no tainted data is allowed to print. Obviously if you start handling user-input prior to this INIT block then that isn't covered but you shouldn't do that anyway. This can be enhanced by using an exception
package Filter::Handle::Tainted;
# Put this code into the package just to have a reasonable
# place to live.
use Filter::Handle qw(subs);
use Taint qw(tainted);
use Exception::Class qw(Filter::Handle::Tainted::TaintException);
INIT {
Filter
\ *STDOUT,
sub {
for (@_) {
next unless tainted( $_ );
# Tainted data was about to be printed to
# the handle. Throw an exception instead.
Filter::Handle::Tainted::TaintException
-> throw( error =>
"Tainted data may not be written to this
+io handle." );
}
};
}
Fun Fun Fun in the Fluffy Chair
-
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.
|