- New SecurityHeadersMiddleware (outermost): CSP with a per-request script nonce, framing (SAMEORIGIN, embeds via frame-ancestors), nosniff, Referrer- and Permissions-Policy. JSON, files and error pages are covered now, not only rendered HTML; headers set by controllers still win. - The inline theme script carries the nonce; flash messages are dismissed via data-dismiss instead of inline onclick handlers, and the flash elements share one template. - reCAPTCHA sources are only allowed when it is enabled. - The embed CSRF exception and framing use the same isEmbed() check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.0 KiB
PHP
28 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* Applies the stored colour scheme before first paint (no flash of the wrong theme).
|
|
* Must be included in <head>. The theme switch (element theme_switch, webroot/js/plenario.js
|
|
* `Theme`) writes the same localStorage key.
|
|
*
|
|
* @var \App\View\AppView $this
|
|
* @var string $key localStorage key (presenter uses its own, the beamer is not the laptop)
|
|
* @var string $fallback Theme without stored choice: '' = follow the system, 'dark' or 'light'
|
|
*
|
|
* Carries the CSP nonce of the request (see \App\Middleware\SecurityHeadersMiddleware).
|
|
*/
|
|
$key ??= 'plenario-theme';
|
|
$fallback ??= '';
|
|
$nonce = (string)$this->getRequest()->getAttribute('cspScriptNonce', '');
|
|
?>
|
|
<script<?= $nonce !== '' ? ' nonce="' . h($nonce) . '"' : '' ?>>
|
|
(function () {
|
|
var theme = <?= json_encode($fallback) ?>;
|
|
try {
|
|
theme = localStorage.getItem(<?= json_encode($key) ?>) || theme;
|
|
} catch (e) {}
|
|
if (theme === 'light' || theme === 'dark') {
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
}
|
|
})();
|
|
</script>
|