I realize that this script takes what I'd call an exclusive method of approval (does the page contain something on a banned list?) rather than an inclusive method (does the page contain something not on an approved list) and is therefore more vulnerable to trickery or changes/ additions to what browsers think is an acceptable javascript event.
I hope this script is useful, but you've been warned. As always, your comments, criticisms and baseless accusations are welcome.
Update
Removed the event list and added dws' suggestion for a regex to search for /on\w+/
Added belg4mit's suggestions :
#! perl -w use HTML::Parser; use LWP::Simple; use URI::Escape; use strict; my $fn = shift; $fn || die "supply a url to parse\n"; my $f = get ($fn) || die "unable to get $fn\n"; HTML::Parser->new( default_h => [\&check_attrs, 'text, tagname, attr'], + )->parse($f ) || die $!; sub check_attrs { my @forbiddenprotos= qw(javascript mocha data); my $line = shift; my $tagname = shift; return unless $tagname; $tagname = uri_unescape($tagname); print "found script tag.\n\t$line\n" if $tagname eq "script"; my $attr = shift; my $attrs = uri_unescape(join " ", keys %$attr); my $attrvals = uri_unescape(join " ", values %$attr); print "events $1 found.\n\t$line\n" if $attrs=~/\b(on\w+)/; foreach (@forbiddenprotos) { print "$_ protocol found.\n\t$line\n" if $attrvals=~/\b$_:/; } print "javascript entity found.\n\t$line\n" if $attrvals=~/\&\{/; }
|
---|
Replies are listed 'Best First'. | |
---|---|
(~OT) WARNING: Live Ammo WAS: Re: Am I javascript or not?
by belg4mit (Prior) on Mar 30, 2002 at 19:48 UTC | |
Re: Am I javascript or not?
by dws (Chancellor) on Mar 30, 2002 at 18:16 UTC | |
by boo_radley (Parson) on Mar 30, 2002 at 18:43 UTC |