Skip to content

Commit 330d9e3

Browse files
authored
Merge pull request #41583 from nextcloud/fix/csp-on-old-ua
2 parents 653b18c + ecf9f0a commit 330d9e3

File tree

4 files changed

+67
-67
lines changed

4 files changed

+67
-67
lines changed

lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
* @since 9.0.0
3838
*/
3939
class EmptyContentSecurityPolicy {
40-
/** @var string Whether JS nonces should be used */
41-
protected $useJsNonce = null;
40+
/** @var string JS nonce to be used */
41+
protected $jsNonce = null;
4242
/** @var bool Whether strict-dynamic should be used */
4343
protected $strictDynamicAllowed = null;
4444
/** @var bool Whether strict-dynamic should be used on script-src-elem */
@@ -116,7 +116,7 @@ public function useStrictDynamicOnScripts(bool $state = false): self {
116116
* @since 11.0.0
117117
*/
118118
public function useJsNonce($nonce) {
119-
$this->useJsNonce = $nonce;
119+
$this->jsNonce = $nonce;
120120
return $this;
121121
}
122122

@@ -463,11 +463,11 @@ public function buildPolicy() {
463463
if (!empty($this->allowedScriptDomains) || $this->evalScriptAllowed || $this->evalWasmAllowed) {
464464
$policy .= 'script-src ';
465465
$scriptSrc = '';
466-
if (is_string($this->useJsNonce)) {
466+
if (is_string($this->jsNonce)) {
467467
if ($this->strictDynamicAllowed) {
468468
$scriptSrc .= '\'strict-dynamic\' ';
469469
}
470-
$scriptSrc .= '\'nonce-'.base64_encode($this->useJsNonce).'\'';
470+
$scriptSrc .= '\'nonce-'.base64_encode($this->jsNonce).'\'';
471471
$allowedScriptDomains = array_flip($this->allowedScriptDomains);
472472
unset($allowedScriptDomains['\'self\'']);
473473
$this->allowedScriptDomains = array_flip($allowedScriptDomains);
@@ -488,7 +488,7 @@ public function buildPolicy() {
488488
}
489489

490490
// We only need to set this if 'strictDynamicAllowed' is not set because otherwise we can simply fall back to script-src
491-
if ($this->strictDynamicAllowedOnScripts && !(is_string($this->useJsNonce) && $this->strictDynamicAllowed)) {
491+
if ($this->strictDynamicAllowedOnScripts && is_string($this->jsNonce) && !$this->strictDynamicAllowed) {
492492
$policy .= 'script-src-elem \'strict-dynamic\' ';
493493
$policy .= $scriptSrc ?? '';
494494
$policy .= ';';

0 commit comments

Comments
 (0)