aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-05-05 17:26:48 +0200
committerGitHub <noreply@github.com>2022-05-05 17:26:48 +0200
commit7718c9776c5903474b8f3cf958cdd18a53b2449e (patch)
treea5b2a2535f7a2aea6fbce361df6a52b3e229ad85
parent0690646d09430ce363b07bc2cd59283e303314eb (diff)
parent18c013d8fc0d95249136799c5c0e67994766d953 (diff)
downloadnextcloud-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
-rw-r--r--lib/private/Security/CSP/ContentSecurityPolicy.php7
-rw-r--r--lib/private/Security/CSP/ContentSecurityPolicyManager.php7
-rw-r--r--lib/public/AppFramework/Http/ContentSecurityPolicy.php2
-rw-r--r--tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php3
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);
});