NAME

Taint::Util - Test for and flip the taint flag without regex matches or eval

SYNOPSIS

#!/usr/bin/env perl -T
use Taint::Util;

# eek!
untaint $ENV{PATH};

# $sv now tainted under taint mode (-T)
taint(my $sv = "hlagh");

# Untaint $sv again
untaint $sv if tainted $sv;

DESCRIPTION

Wraps perl's internal routines for checking and setting the taint flag and thus does not rely on regular expressions for untainting or odd tricks involving eval and kill for checking whether data is tainted, instead it checks and flips a flag on the scalar in-place.

FUNCTIONS

tainted

Returns a boolean indicating whether a scalar is tainted. Always false when not under taint.

taint & untaint

Taints or untaints given values, arrays will be flattened and their elements tainted, likewise with the values of hashes (keys can't be tainted, see perlsec). Returns no value (which evaluates to false).

untaint(%ENV);                  # Untaints the environment
taint(my @hlagh = qw(a o e u)); # elements of @hlagh now tainted

References (being scalars) can also be tainted, a stringified reference reference raises an error where a tainted scalar would.

taint(my $ar = \@hlagh);
system echo => $ar;      # err: Insecure dependency in system

The author can't think of any case where tainting references would actually be useful.

File handles can also be tainted, but this is equally useless as the handle itself and not lines retrieved from it will be tainted.

taint(*DATA);    # *DATA tainted
my $ln = <DATA>; # $ln not tainted

EXPORTS

Exports tainted, taint and untaint by default. Individual functions can be exported by specifying them in the use list, to export none use ().

HISTORY

I wrote this when implementing re::engine::Plugin so that someone writing a custom regex engine with it wouldn't have to rely on perl regexps for untainting capture variables, which would be a bit odd.

SEE ALSO

perlsec

AUTHOR

Ævar Arnfjörð Bjarmason <avar@cpan.org>

LICENSE

Copyright 2007 Ævar Arnfjörð Bjarmason.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.