line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::FormValidator::Filters::HTMLStrip; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27322
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
54
|
|
4
|
1
|
|
|
1
|
|
1046
|
use HTML::Strip; |
|
1
|
|
|
|
|
13669
|
|
|
1
|
|
|
|
|
328
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=pod |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Data::FormValidator::Filters::HTMLStrip - Filter that removes html tags from input |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Data::FormValidator::Filters::HTMLStrip qw( html_strip ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Build a Data::FormValidator Profile: |
17
|
|
|
|
|
|
|
my $my_profile = { |
18
|
|
|
|
|
|
|
required => qw( text ), |
19
|
|
|
|
|
|
|
field_filters => { |
20
|
|
|
|
|
|
|
text => html_strip, |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Be sure to use a CGI.pm object as the form input |
25
|
|
|
|
|
|
|
# when using this filter |
26
|
|
|
|
|
|
|
my $q = new CGI; |
27
|
|
|
|
|
|
|
my $dfv = Data::FormValidator->check($q,$my_profile); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This is a Data::FormaValidator filter that acts as a wrapper for HTML::Strip. |
32
|
|
|
|
|
|
|
It removes html tags from variable data to help protect against cross-site |
33
|
|
|
|
|
|
|
scripting attacks. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
14
|
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK ); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
161
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
BEGIN { |
40
|
1
|
|
|
1
|
|
16
|
require Exporter; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
2
|
$VERSION = '0.13'; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
69
|
@ISA = qw( Exporter ); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
3
|
@EXPORT = (); |
47
|
1
|
|
|
|
|
235
|
@EXPORT_OK = qw( html_strip ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 FILTERS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 html_strip |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This will create a filter that will strip html tags from |
58
|
|
|
|
|
|
|
the value of filtered variables. This assists in protecting cross site |
59
|
|
|
|
|
|
|
scripting exploits from users attempting to embed html tags into input |
60
|
|
|
|
|
|
|
fields. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub html_strip { |
65
|
0
|
|
|
0
|
1
|
|
my %options = @_; |
66
|
|
|
|
|
|
|
return |
67
|
0
|
|
|
0
|
|
|
sub { return __clean_data( shift, %options ) }; |
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub __clean_data { |
71
|
0
|
|
|
0
|
|
|
my $data = shift; |
72
|
0
|
|
|
|
|
|
my @the_rest = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $hs = HTML::Strip->new(@the_rest); |
75
|
0
|
|
|
|
|
|
my $clean = $hs->parse( $data ); |
76
|
0
|
|
|
|
|
|
$hs->eof(); |
77
|
0
|
|
|
|
|
|
$clean =~ s/>/>\;/g; |
78
|
0
|
|
|
|
|
|
$clean =~ s/<\;/g; |
79
|
0
|
|
|
|
|
|
return $clean |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |