line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::XSSLint; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
83476
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
89
|
|
4
|
2
|
|
|
2
|
|
11
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
162
|
|
5
|
|
|
|
|
|
|
$VERSION = 0.01; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require LWP::UserAgent; |
8
|
2
|
|
|
2
|
|
10
|
use base qw(LWP::UserAgent); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
2224
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
111298
|
use Digest::MD5; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
132
|
|
11
|
2
|
|
|
2
|
|
1421
|
use HTML::XSSLint::Result; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
57
|
|
12
|
2
|
|
|
2
|
|
2201
|
use HTML::Form; |
|
2
|
|
|
|
|
40788
|
|
|
2
|
|
|
|
|
69
|
|
13
|
2
|
|
|
2
|
|
21
|
use HTTP::Request; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
14
|
2
|
|
|
2
|
|
15
|
use URI; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1297
|
|
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
|
0
|
sub _croak { require Carp; Carp::croak(@_); } |
|
0
|
|
|
|
|
0
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub audit { |
19
|
2
|
|
|
2
|
0
|
1017979
|
my($self, $uri) = @_; |
20
|
2
|
|
|
|
|
34
|
$uri = URI->new($uri); |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
28981
|
my $request = HTTP::Request->new(GET => $uri); |
23
|
2
|
|
|
|
|
521
|
my $response = $self->request($request); |
24
|
2
|
50
|
|
|
|
152484
|
$response->is_success or _croak("Can't fetch $uri"); |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
40
|
my @forms = HTML::Form->parse($response->content, $uri); |
27
|
2
|
100
|
|
|
|
17824
|
return wantarray ? (map $self->do_audit($_), @forms) : $self->do_audit($forms[0]); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub do_audit { |
31
|
3
|
|
|
3
|
0
|
9
|
my($self, $form) = @_; |
32
|
3
|
|
|
|
|
15
|
my $params = $self->make_params($form->inputs); |
33
|
3
|
|
|
|
|
15
|
my $request = $self->fillin_and_click($form, $params); |
34
|
3
|
|
|
|
|
2314
|
my $response = $self->request($request); |
35
|
3
|
50
|
|
|
|
20306
|
$response->is_success or _croak("Can't fetch " . $form->action); |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
228
|
my @names = $self->compare($response->content, $params); |
38
|
3
|
|
|
|
|
51
|
return HTML::XSSLint::Result->new( |
39
|
|
|
|
|
|
|
form => $form, |
40
|
|
|
|
|
|
|
names => \@names, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub make_params { |
45
|
3
|
|
|
3
|
0
|
28
|
my($self, @inputs) = @_; |
46
|
7
|
|
|
|
|
97
|
my %params = map { |
47
|
7
|
50
|
|
|
|
88
|
my $value = $self->random_string; |
48
|
7
|
|
|
|
|
26
|
($_->name => "<>$value"); |
49
|
|
|
|
|
|
|
} grep { |
50
|
3
|
|
|
|
|
10
|
defined($_->name) && length($_->name) |
51
|
|
|
|
|
|
|
} @inputs; |
52
|
3
|
|
|
|
|
41
|
return \%params; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub random_string { |
56
|
7
|
|
|
7
|
0
|
12
|
my $self = shift; |
57
|
7
|
|
|
|
|
122
|
return substr(Digest::MD5::md5_hex(rand() . {} . $$ . time), 0, 8); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub fillin_and_click { |
61
|
3
|
|
|
3
|
0
|
7
|
my($self, $form, $params) = @_; |
62
|
3
|
|
|
|
|
23
|
local *HTML::Form::ListInput::value = \&hf_li_value; # hack it |
63
|
3
|
|
|
|
|
41
|
for my $name (keys %$params) { |
64
|
7
|
|
|
|
|
327
|
$form->value($name => $params->{$name}); |
65
|
|
|
|
|
|
|
} |
66
|
3
|
|
|
|
|
305
|
return $form->click; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub compare { |
70
|
3
|
|
|
3
|
0
|
50
|
my($self, $html, $params) = @_; |
71
|
7
|
|
|
|
|
15
|
return grep { |
72
|
3
|
|
|
|
|
16
|
my $value = $params->{$_}; |
73
|
7
|
|
|
|
|
221
|
$html =~ /$value/; |
74
|
|
|
|
|
|
|
} keys %$params; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub hf_li_value { |
78
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
my $old = $self->{value}; |
80
|
0
|
0
|
|
|
|
|
$self->{value} = shift if @_; |
81
|
0
|
|
|
|
|
|
$old; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
__END__ |