Skip to content

Commit

Permalink
🐛 since panel has no nonces yet (issue pending) automatic disabling w…
Browse files Browse the repository at this point in the history
…as needed.

getkirby/kirby#1527

Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Sep 1, 2019
1 parent 23e6612 commit fb985e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions classes/SecurityHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ final class SecurityHeaders

public function __construct(array $options = [])
{
$isPanel = strpos(
kirby()->request()->url()->toString(),
kirby()->urls()->panel
) !== false;
$panelHasNonces = method_exists(kirby()->system(), 'nonces');
$enabled = !kirby()->system()->isLocal() && ($isPanel && $panelHasNonces);

$defaults = [
'debug' => option('debug'),
'loader' => option('bnomei.securityheaders.loader'),
'enabled' => option('enabled', !kirby()->system()->isLocal()),
'enabled' => option('enabled', $enabled),
'headers' => option('bnomei.securityheaders.headers'),
'panelnonces' => method_exists(kirby()->system(), 'nonces') ? kirby()->system()->nonces() : [],
'panelnonces' => $panelHasNonces ? kirby()->system()->nonces() : [],
'setter' => option('bnomei.securityheaders.setter'),
];
$this->options = array_merge($defaults, $options);
Expand Down Expand Up @@ -153,7 +160,7 @@ public function sendHeaders(): bool
}

// from cspbuilder
if($this->cspBuilder) {
if ($this->cspBuilder) {
$this->cspBuilder->sendCSPHeader();
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-security-headers",
"type": "kirby-plugin",
"version": "2.0.0",
"version": "2.0.1",
"license": "MIT",
"description": "Kirby 3 Plugin for easier Security Headers setup",
"authors": [
Expand Down

0 comments on commit fb985e8

Please sign in to comment.