diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-05-05 17:26:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-05 17:26:48 +0200 |
commit | 7718c9776c5903474b8f3cf958cdd18a53b2449e (patch) | |
tree | a5b2a2535f7a2aea6fbce361df6a52b3e229ad85 | |
parent | 0690646d09430ce363b07bc2cd59283e303314eb (diff) | |
parent | 18c013d8fc0d95249136799c5c0e67994766d953 (diff) | |
download | nextcloud-server-7718c9776c5903474b8f3cf958cdd18a53b2449e.tar.gz nextcloud-server-7718c9776c5903474b8f3cf958cdd18a53b2449e.zip |
Merge pull request #32113 from nextcloud/bugfix/noid/fix-csp-merging-bools
Add CSP policy merge priority for booleans
4 files changed, 16 insertions, 3 deletions
diff --git a/lib/private/Security/CSP/ContentSecurityPolicy.php b/lib/private/Security/CSP/ContentSecurityPolicy.php index 8a72934d4c9..8d9551c8978 100644 --- a/lib/private/Security/CSP/ContentSecurityPolicy.php +++ b/lib/private/Security/CSP/ContentSecurityPolicy.php @@ -246,6 +246,13 @@ class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy } /** + * @return boolean + */ + public function isStrictDynamicAllowed(): bool { + return $this->strictDynamicAllowed; + } + + /** * @param boolean $strictDynamicAllowed */ public function setStrictDynamicAllowed(bool $strictDynamicAllowed) { diff --git a/lib/private/Security/CSP/ContentSecurityPolicyManager.php b/lib/private/Security/CSP/ContentSecurityPolicyManager.php index ff770435eda..4930dcb759c 100644 --- a/lib/private/Security/CSP/ContentSecurityPolicyManager.php +++ b/lib/private/Security/CSP/ContentSecurityPolicyManager.php @@ -82,7 +82,12 @@ class ContentSecurityPolicyManager implements IContentSecurityPolicyManager { $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); } elseif (\is_bool($value)) { - $defaultPolicy->$setter($value); + $getter = 'is'.ucfirst($name); + $currentValue = $defaultPolicy->$getter(); + // true wins over false + if ($value > $currentValue) { + $defaultPolicy->$setter($value); + } } } diff --git a/lib/public/AppFramework/Http/ContentSecurityPolicy.php b/lib/public/AppFramework/Http/ContentSecurityPolicy.php index 3a91e3dc2a7..0e3a6a705d5 100644 --- a/lib/public/AppFramework/Http/ContentSecurityPolicy.php +++ b/lib/public/AppFramework/Http/ContentSecurityPolicy.php @@ -45,7 +45,7 @@ class ContentSecurityPolicy extends EmptyContentSecurityPolicy { /** @var bool Whether eval in JS scripts is allowed */ protected $evalScriptAllowed = false; /** @var bool Whether strict-dynamic should be set */ - protected $strictDynamicAllowed = null; + protected $strictDynamicAllowed = false; /** @var array Domains from which scripts can get loaded */ protected $allowedScriptDomains = [ '\'self\'', diff --git a/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php b/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php index e5cf9ea9e1f..082ef46330d 100644 --- a/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php +++ b/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php @@ -87,6 +87,7 @@ class ContentSecurityPolicyManagerTest extends TestCase { $policy->addAllowedFontDomain('mydomain.com'); $policy->addAllowedImageDomain('anotherdomain.de'); $policy->useStrictDynamic(true); + $policy->allowEvalScript(true); $e->addPolicy($policy); }); @@ -96,7 +97,7 @@ class ContentSecurityPolicyManagerTest extends TestCase { $policy->addAllowedFontDomain('example.com'); $policy->addAllowedImageDomain('example.org'); $policy->allowInlineScript(true); - $policy->allowEvalScript(true); + $policy->allowEvalScript(false); $e->addPolicy($policy); }); |