Skip to content

Commit

Permalink
remove useless hasing of the files
Browse files Browse the repository at this point in the history
  • Loading branch information
zero-24 committed Jul 27, 2019
1 parent 74e3d98 commit 3ddbd4b
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions plugins/system/httpheaders/httpheaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,13 @@ public function applyHashesToCspRule(): void
$scriptHashesEnabled = (int) $this->comCspParams->get('script_hashes_enabled', 0);
$styleHashesEnabled = (int) $this->comCspParams->get('style_hashes_enabled', 0);
$headData = Factory::getDocument()->getHeadData();
$baseUrl = Uri::getInstance()->toString(['scheme', 'user', 'pass', 'host', 'port']);
$scriptHashes = [];
$styleHashes = [];

if ($scriptHashesEnabled)
{
// Generate the hashes for the script-src
$fileBasedScripts = is_array($headData['scripts']) ? $headData['scripts'] : [];
$inlineScripts = is_array($headData['script']) ? $headData['script'] : [];

foreach ($fileBasedScripts as $scriptUrl => $attibs)
{
$scriptHashes[] = "'sha256-" . base64_encode(hash('sha256', file_get_contents($base . $scriptUrl))) . "'";
}
$inlineScripts = is_array($headData['script']) ? $headData['script'] : [];

foreach ($inlineScripts as $type => $scriptContent)
{
Expand All @@ -197,13 +190,7 @@ public function applyHashesToCspRule(): void
if ($styleHashesEnabled)
{
// Generate the hashes for the style-src
$fileBasedStylesheets = is_array($headData['styleSheets']) ? $headData['styleSheets'] : [];
$inlineStyles = is_array($headData['style']) ? $headData['style'] : [];

foreach ($fileBasedStylesheets as $stylesheetUrl => $attibs)
{
$styleHashes[] = "'sha256-" . base64_encode(hash('sha256', file_get_contents($base . $stylesheetUrl))) . "'";
}
$inlineStyles = is_array($headData['style']) ? $headData['style'] : [];

foreach ($inlineStyles as $type => $styleContent)
{
Expand Down

0 comments on commit 3ddbd4b

Please sign in to comment.