| 1 | package Data::FormValidator::Filters::HTMLStrip; | ||
| 2 | |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use HTML::Strip; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | 2 | ▶ | use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 38 | |||
| 39 | 2 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 40 | 2 | require Exporter; | |
| 41 | |||
| 42 | 2 | $VERSION = '0.13'; | |
| 43 | |||
| 44 | 2 | @ISA = qw( Exporter ); | |
| 45 | |||
| 46 | 2 | @EXPORT = (); | |
| 47 | 2 | @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 | 0 | ▶ | sub html_strip { |
|
Subroutine
html_strip: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 65 | 0 | my %options = @_; | |
| 66 | return | ||
| 67 | 0 | ▶ | sub { return __clean_data( shift, %options ) }; |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 68 | } | ||
| 69 | |||
| 70 | 0 | ▶ | sub __clean_data { |
|
Subroutine
__clean_data: not called CC=1 SCAR=6.9
| |||
| 71 | 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 | 2 | 1; | |
| 83 | |||
| 84 | __END__ | ||