Skip to content

Commit 4892849

Browse files
committed
fix: CSP style nonce is added even if honeypot is not attached
The tag like this was added in <head> tag in every page. <style nonce="ccdd15247e8da0a5b9023a5e">#hpc { display:none }</style>
1 parent a9cd190 commit 4892849

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

system/Honeypot/Honeypot.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ public function attachHoneypot(ResponseInterface $response)
8989

9090
$prepField = $this->prepareTemplate($this->config->template);
9191

92-
$body = $response->getBody();
93-
$body = str_ireplace('</form>', $prepField . '</form>', $body);
92+
$bodyBefore = $response->getBody();
93+
$bodyAfter = str_ireplace('</form>', $prepField . '</form>', $bodyBefore);
9494

95-
if ($response->getCSP()->enabled()) {
95+
if ($response->getCSP()->enabled() && ($bodyBefore !== $bodyAfter)) {
9696
// Add style tag for the container tag in the head tag.
97-
$style = '<style ' . csp_style_nonce() . '>#' . $this->config->containerId . ' { display:none }</style>';
98-
$body = str_ireplace('</head>', $style . '</head>', $body);
97+
$style = '<style ' . csp_style_nonce() . '>#' . $this->config->containerId . ' { display:none }</style>';
98+
$bodyAfter = str_ireplace('</head>', $style . '</head>', $bodyAfter);
9999
}
100100

101-
$response->setBody($body);
101+
$response->setBody($bodyAfter);
102102
}
103103

104104
/**

0 commit comments

Comments
 (0)