1Taint(3)              User Contributed Perl Documentation             Taint(3)
2
3
4

NAME

6       Test::Taint - Tools to test taintedness
7

VERSION

9       Version 1.08
10

SYNOPSIS

12           taint_checking_ok();        # We have to have taint checking on
13           my $id = "deadbeef";        # Dummy session ID
14           taint( $id );               # Simulate it coming in from the web
15           tainted_ok( $id );
16           $id = validate_id( $id );   # Your routine to check the $id
17           untainted_ok( $id );        # Did it come back clean?
18           ok( defined $id );
19

DESCRIPTION

21       Tainted data is data that comes from an unsafe source, such as the
22       command line, or, in the case of web apps, any GET or POST
23       transactions.  Read the perlsec man page for details on why tainted
24       data is bad, and how to untaint the data.
25
26       When you're writing unit tests for code that deals with tainted data,
27       you'll want to have a way to provide tainted data for your routines to
28       handle, and easy ways to check and report on the taintedness of your
29       data, in standard Test::More style.
30

"Test::More"-style Functions

32       All the "xxx_ok()" functions work like standard "Test::More"-style
33       functions, where the last parm is an optional message, it outputs ok or
34       not ok, and returns a boolean telling if the test passed.
35
36   taint_checking_ok( [$message] )
37       Test::More-style test that taint checking is on.  This should probably
38       be the first thing in any *.t file that deals with taintedness.
39
40   tainted_ok( $var [, $message ] )
41       Checks that $var is tainted.
42
43           tainted_ok( $ENV{FOO} );
44
45   untainted_ok( $var [, $message ] )
46       Checks that $var is not tainted.
47
48           my $foo = my_validate( $ENV{FOO} );
49           untainted_ok( $foo );
50
51   tainted_ok_deeply( $var [, $message ] )
52       Checks that $var is tainted.  If $var is a reference, it recursively
53       checks every variable to make sure they are all tainted.
54
55           tainted_ok_deeply( \%ENV );
56
57   untainted_ok_deeply( $var [, $message ] )
58       Checks that $var is not tainted.  If $var is a reference, it
59       recursively checks every variable to make sure they are all not
60       tainted.
61
62           my %env = my_validate( \%ENV );
63           untainted_ok_deeply( \%env );
64

Helper Functions

66       These are all helper functions.  Most are wrapped by an "xxx_ok()"
67       counterpart, except for "taint" which actually does something, instead
68       of just reporting it.
69
70   taint_checking()
71       Returns true if taint checking is enabled via the -T flag.
72
73   tainted( $var )
74       Returns boolean saying if $var is tainted.
75
76   tainted_deeply( $var )
77       Returns boolean saying if $var is tainted.  If $var is a reference it
78       recursively checks every variable to make sure they are all tainted.
79
80   taint( @list )
81       Marks each (apparently) taintable argument in @list as being tainted.
82
83       References can be tainted like any other scalar, but it doesn't make
84       sense to, so they will not be tainted by this function.
85
86       Some "tie"d and magical variables may fail to be tainted by this
87       routine, try as it may.
88
89   taint_deeply( @list )
90       Similar to "taint", except that if any elements in @list are
91       references, it walks deeply into the data structure and marks each
92       taintable argument as being tainted.
93
94       If any variables are "tie"d this will taint all the scalars within the
95       tied object.
96

AUTHOR

98       Written by Andy Lester, "<andy@petdance.com>".
99
101       Copyright 2004-2019, Andy Lester.
102
103       You may use, modify, and distribute this package under the same terms
104       as Perl itself.
105
106
107
108perl v5.32.0                      2020-07-28                          Taint(3)
Impressum