From b1bbf4055d15d31020b6dbf1ad9e187e24308d15 Mon Sep 17 00:00:00 2001 From: spaghetti Date: Fri, 30 Sep 2016 22:03:27 -0400 Subject: [PATCH] Add sub-resource integrity to scripts This is not particularly useful but it was fun --- design/privateheader.php | 46 ++++++++++++++++++++-------------------------- design/publicheader.php | 21 ++++++++++++++------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/design/privateheader.php b/design/privateheader.php index 6d3b793..5667c2f 100755 --- a/design/privateheader.php +++ b/design/privateheader.php @@ -60,30 +60,24 @@ if ($UseTooltipster) { ?> - - - - + - + get_value("script_stats_$Script")) === false || $ScriptStats['mtime'] != filemtime(STATIC_SERVER."functions/$Script.js")) { + $ScriptStats['mtime'] = filemtime(STATIC_SERVER."functions/$Script.js"); + $ScriptStats['hash'] = base64_encode(hash_file(INTEGRITY_ALGO, STATIC_SERVER."functions/$Script.js", true)); + $ScriptStats['algo'] = INTEGRITY_ALGO; + G::$Cache->cache_value("script_stats_$Script", $ScriptStats); + } ?> - - - + - - - - - - - +get_value("script_stats_$Script")) === false || $ScriptStats['mtime'] != filemtime(STATIC_SERVER."functions/$Script.js")) { + $ScriptStats['mtime'] = filemtime(STATIC_SERVER."functions/$Script.js"); + $ScriptStats['hash'] = base64_encode(hash_file(INTEGRITY_ALGO, STATIC_SERVER."functions/$Script.js", true)); + $ScriptStats['algo'] = INTEGRITY_ALGO; + G::$Cache->cache_value("script_stats_$Script", $ScriptStats); + } +?> + +