Skip to content

Commit 655e6b6

Browse files
committed
Simplifying code according to review.
1 parent 40836bd commit 655e6b6

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

system/HTTP/ContentSecurityPolicy.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,7 @@ public function getScriptNonce(): string
427427
*/
428428
public function finalize(ResponseInterface $response)
429429
{
430-
if ($this->autoNonce) {
431-
$this->generateNonces($response);
432-
} elseif (! $this->enabled()) {
433-
// If autoNonce is disabled and CSP is not enabled, we should still remove any nonce tags from the body to prevent confusion.
434-
$body = (string) $response->getBody();
435-
436-
if ($body !== '') {
437-
$body = str_replace([$this->styleNonceTag, $this->scriptNonceTag], '', $body);
438-
$response->setBody($body);
439-
}
440-
}
430+
$this->generateNonces($response);
441431

442432
$this->buildHeaders($response);
443433
}
@@ -900,6 +890,10 @@ protected function addOption($options, string $target, ?bool $explicitReporting
900890
*/
901891
protected function generateNonces(ResponseInterface $response)
902892
{
893+
if ($this->enabled() && ! $this->autoNonce) {
894+
return;
895+
}
896+
903897
$body = (string) $response->getBody();
904898

905899
if ($body === '') {

0 commit comments

Comments
 (0)