summaryrefslogtreecommitdiff
path: root/html5_events.pl
diff options
context:
space:
mode:
authorhackademix2018-07-01 01:01:23 +0200
committerhackademix2018-07-01 01:01:23 +0200
commiteceae7187a6f0e9510bc1165f6977256b87f490f (patch)
treed943f1ec73c09efa70954dcedb55eac82a726148 /html5_events.pl
downloadnoscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.gz
noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.xz
noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.zip
Initial commit starting at version 10.1.8.3rc4.
Diffstat (limited to 'html5_events.pl')
-rw-r--r--html5_events.pl99
1 files changed, 99 insertions, 0 deletions
diff --git a/html5_events.pl b/html5_events.pl
new file mode 100644
index 0000000..1fb02fe
--- /dev/null
+++ b/html5_events.pl
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+use strict;
+
+require LWP::UserAgent;
+use LWP::Simple;
+use RegExp::List;
+use File::stat;
+use File::Basename;
+use List::MoreUtils qw(uniq);
+
+my $HTML5_URL = "https://hg.mozilla.org/mozilla-central/raw-file/tip/parser/html/nsHtml5AtomList.h";
+my $GECKO_URL = "https://hg.mozilla.org/mozilla-central/raw-file/tip/xpcom/ds/nsGkAtomList.h";
+
+my $HERE = dirname($0);
+my $SOURCE_FILE = $HERE . '/src/xss/InjectionChecker.js';
+
+sub create_re
+{
+ my $cache = "$HERE/html5_events.re";
+ my $sb = stat($cache);
+
+ if ($sb && time() - $sb->mtime < 86400)
+ {
+ open IN, "<$cache";
+ my @content = <IN>;
+ close IN;
+ return $content[0];
+ }
+
+ sub fetch_url
+ {
+ my $url = shift(@_);
+ my $ua = LWP::UserAgent->new;
+ $ua->agent('Mozilla/5.0');
+ $ua->ssl_opts('verify_hostname' => 0);
+ my $res = $ua->get($url);
+ if ($res->is_success)
+ {
+ return $res->decoded_content;
+ }
+ else
+ {
+ my $err = $res->content;
+ my $ca_file = $ua->ssl_opts('SSL_ca_file');
+ die ("Could not fetch $url: $err\n$ca_file");
+ }
+ }
+
+
+ my $content = # fetch_url($HTML5_URL) .
+ fetch_url($GECKO_URL);
+
+ $content = join("\n", grep(/^(?:HTML5|GK)_ATOM.*"on\w+"/, split(/[\n\r]/, $content)));
+
+ $content =~ s/.*"(on\w+)".*/$1 /g;
+ $content =~ s/\s+/ /g;
+ $content =~ s/^\s+|\s+$//g;
+
+ my $l = Regexp::List->new;
+ my $re = $l->list2re(uniq(split(' ', $content)));
+ $re =~ s/\(\?[-^]\w+:(.*)\)/$1/;
+ open (OUT, ">$cache");
+ print OUT $re;
+ close OUT;
+ $re;
+}
+
+sub patch
+{
+ my $src = shift;
+ my $dst = "$src.tmp";
+ my $re = create_re();
+ my $must_replace = 0;
+ print "Patching $src...\n";
+ open IN, "<$src" or die ("Can't open $src!");
+ open OUT, ">$dst" or die ("Can't open $dst!");
+
+ while (<IN>)
+ {
+ my $line = $_;
+ $must_replace = $line ne $_ if s/^(\s*const IC_EVENT_PATTERN\s*=\s*")([^"]+)/$1$re/;
+
+ print OUT $_;
+ }
+ close IN;
+ close OUT;
+
+ if ($must_replace) {
+ rename $dst, $src;
+ print "Patched.\n";
+ }
+ else
+ {
+ unlink $dst;
+ print "Nothing to do.\n";
+ }
+}
+
+patch($SOURCE_FILE);