From 7e8f9a5c2eaddad49aebc6911706533ef64db1eb Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Wed, 15 Apr 2015 18:47:26 +0300 Subject: [PATCH] Use Subresource Integrity --- make_static.PL | 10 +++++++++- tmpl/skel.en | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/make_static.PL b/make_static.PL index 10532b9..758efc1 100644 --- a/make_static.PL +++ b/make_static.PL @@ -5,8 +5,9 @@ use warnings; use CSS::Minifier::XS qw//; use JavaScript::Minifier::XS qw//; +use Digest::SHA qw/sha256_base64/; use IO::Compress::Gzip qw/gzip/; -use File::Slurp qw/read_file write_file/; +use File::Slurp qw/read_file write_file edit_file_lines/; mkdir 'static'; mkdir 'static/css'; @@ -57,3 +58,10 @@ for () { last } } + +edit_file_lines { + my ($file) = m,(static.*\.(?:css|js)),; + return unless $file; + my $hash = sha256_base64 scalar read_file $file; + s/integrity=".*"/integrity="sha256-$hash="/; +} 'tmpl/skel.en' diff --git a/tmpl/skel.en b/tmpl/skel.en index 3006e14..459d37b 100644 --- a/tmpl/skel.en +++ b/tmpl/skel.en @@ -3,10 +3,10 @@ - - - - + + + +
-- 2.30.2