diff options
| author | 2025-08-09 21:47:39 +0200 | |
|---|---|---|
| committer | 2025-08-09 21:47:39 +0200 | |
| commit | 2b85a50ed72982ab0c0f9ef98c7ed1e15f21bf5f (patch) | |
| tree | 7bb8412d5b14142a384e0da8cb6255802935d053 /p/scripts | |
| parent | 1030973d903c746d4fb10b863c7b9aebb5c448e1 (diff) | |
Show warning when unsafe CSP policy is in use (#7804)
* Show warning when unsafe CSP policy is in use
* Fix bare markdown URL
* i18n: fr
* Minor i18n: fr
* Add target="_blank" to i18n strings
---------
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'p/scripts')
| -rw-r--r-- | p/scripts/main.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js index 1e35c84fa..c9f856c73 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -2181,6 +2181,26 @@ function init_normal() { }); } +function init_csp_alert() { + if (!context.admin || context.suppress_csp_warning) { + return; + } + + try { + // eslint-disable-next-line no-new-func + Function(); + } catch (_) { + // Exit if 'script-src' is set and 'unsafe-eval' isn't set in CSP + return; + } + + document.body.insertAdjacentHTML('afterbegin', ` + <div class="alert alert-error"> + <span>${context.i18n.unsafe_csp_header}</span> + </div> + `); +} + function init_main_beforeDOM() { history.scrollRestoration = 'manual'; document.scrollingElement.scrollTop = 0; @@ -2193,6 +2213,7 @@ function init_main_beforeDOM() { function init_main_afterDOM() { removeFirstLoadSpinner(); init_notifications(); + init_csp_alert(); init_confirm_action(); const stream = document.getElementById('stream'); if (stream) { |
