From 527a9d27a53b4bd33905b3275fdc4dac420a0b95 Mon Sep 17 00:00:00 2001 From: Lucas Siebels Date: Fri, 2 Aug 2024 16:04:12 +0200 Subject: [PATCH] fix: build content header correctly --- CHANGELOG.md | 16 ++++++++++++++++ .../Model/Policy/Renderer/CspHeaderSplitter.php | 7 +++---- composer.json | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eabf40..cc0c063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,27 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + ### Added + ### Changed + ### Removed + ### Fixed + +## [1.0.1] - 2020-01-01 + +### Fixed + +- Fixed issue where the fetch directive was added twice to the CSP header content. + +## [1.0.0] - 2024-08-02 + +[1.0.1]: https://github.com/basecom/magento2-csp-split-header/compare/v1.0.0...v1.0.1 +[1.0.0]: https://github.com/basecom/magento2-csp-split-header/releases/tag/v1.0.0 diff --git a/Plugin/Model/Policy/Renderer/CspHeaderSplitter.php b/Plugin/Model/Policy/Renderer/CspHeaderSplitter.php index 73f90d1..b46b763 100644 --- a/Plugin/Model/Policy/Renderer/CspHeaderSplitter.php +++ b/Plugin/Model/Policy/Renderer/CspHeaderSplitter.php @@ -53,7 +53,7 @@ public function afterRender( if ($isHeaderSplittingEnabled) { $this->registerCspHeaderPlugins($response); - $this->splitUpCspHeaders($response, $policy->getId(), $policyValue); + $this->splitUpCspHeaders($response, $policyValue); } else { if ($maxHeaderSize >= $currentHeaderSize) { $response->setHeader($headerName, $policyValue, true); @@ -87,7 +87,7 @@ private function registerCspHeaderPlugins(HttpResponse $response): void /** * Make sure that the CSP headers are handled as several headers ("multi-header") */ - private function splitUpCspHeaders(HttpResponse $response, string $policyId, string $policyValue): void + private function splitUpCspHeaders(HttpResponse $response, string $policyValue): void { $headerName = $this->getHeaderName($response); @@ -95,12 +95,11 @@ private function splitUpCspHeaders(HttpResponse $response, string $policyId, str return; } - $newHeader = $policyId.' '.$policyValue.';'; $maxHeaderSize = $this->config->getMaxHeaderSize(); $newHeaderSize = strlen($policyValue); if ($newHeaderSize <= $maxHeaderSize) { - $this->contentHeaders[] = $newHeader; + $this->contentHeaders[] = $policyValue; } else { $this->logger->error( sprintf( diff --git a/composer.json b/composer.json index c05f0df..954b4cc 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "basecom/magento2-csp-split-header", - "version": "1.0.0", + "version": "1.0.1", "description": "N/A", "type": "magento2-module", "license": [