fix(web): self-host CDN scripts and drop script-src 'unsafe-inline' #422
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/BUNYIP-424-self-host-scripts-drop-unsafe-inline"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
bunyip-web loaded htmx from unpkg.com and Font Awesome from its kit loader at kit.fontawesome.com, neither with an
integrityattribute, and its CSP carriedscript-src 'self' 'unsafe-inline' https://unpkg.com https://kit.fontawesome.com. That was a standing remote-code-execution grant on the origin that holds the session: the kit rotates its own contents by design and cannot carry SRI, unpkg resolves htmx from npm at request time, and'unsafe-inline'meant CSP was no barrier to any future reflected-XSS bug in the SSR pages either. The cookies are httpOnly, but injected JS does not need to read them - it issues same-origin fetches the browser attaches them to.Both libraries are now vendored under
bunyip-web/assets/vendor/with the version in the path so an upgrade is a visible diff: htmx 2.0.3 (byte-identical to the published dist, sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq) and the Font Awesome 6.7.2 Free webfont build (core + solid + regular CSS and their woff2/ttf faces) replacing the kit loader.Every inline
<script>body and everyon*=handler moved intobunyip-web/assets/js/: theme.js (flash prevention + the theme / high-contrast toggles, loaded synchronously so the stored theme lands before first paint), app.js (toast, OTP autosubmit, profile-menu dismissal, confirm-on-submit, copy-to-clipboard, dialogs, the feedback launcher, delayed redirect/reload), avatar-picker.js, sse.js, password.js, and admin-users.js. The markup now opts in through data-* attributes handled by delegated listeners, so server-supplied values (dialog ids, copy commands, confirm text, the SSE origin) reach the browser as passive attributes instead of interpolated JavaScript.bunyip-web/src/security.rstightens toscript-src 'self'and dropshttps://ka-f.fontawesome.comfrom font-src and connect-src now that the icon fonts are same-origin. The Google Fonts stylesheet stays remote: it is style-src, not script-src, and self-hosting those two families is a separate change.Two tests enforce the removal mechanically.
policy_script_src_is_self_onlypins the directive to exactly'self'and asserts no CDN host survives anywhere in the policy.no_inline_script_or_event_handlers_in_viewsscans every non-test line of bunyip-web/src for an inline<script>body, anon*=attribute, or an off-origin<script src>and fails with file:line if one reappears.document_head_loads_only_first_party_scriptsasserts the same at render time.#BUNYIP-424