Enforce CSP without unsafe-inline, and close out the remaining retest items
CI / build (push) Has been cancelled
CI / build (push) Has been cancelled
F-03: the legacy markup's 77 onclick="" attributes were the reason script-src still needed 'unsafe-inline', which let injected inline script/handlers run right past the policy. Migrated them to data-page/data-action markers handled by a single delegated click listener in siteController.js, dropped 'unsafe-inline' from script-src, and switched both server/index.mjs and vercel.json from Content-Security-Policy-Report-Only to enforcing. style-src keeps 'unsafe-inline' — that governs inline style="" attributes used throughout, a separate CSS-injection concern out of scope here. Verified against the built site with a real headless-Chromium run: nav, company dropdown, mobile menu, the demo modal (open/close/overlay-click/ inner-click), the modal's contact-page link, and the scroll-hint all still work, with zero console errors. F-10: confirmed via npm audit fix --dry-run that no non-breaking update remains (vite and react-router-dom both need a major bump, left deferred). Added npm audit to CI — full report for visibility, gated on critical only so it doesn't block on the already-tracked moderate/high advisories. F-11: uploaded PDFs now serve with Content-Disposition: attachment instead of rendering inline from the site's own origin. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
// BlackDice site controller — ported from the original vanilla js/main.js.
|
||||
// Function declarations are exposed on window so the inline onclick handlers in the
|
||||
// legacy markup (goPage(event), showDemo(), etc.) continue to resolve.
|
||||
// The legacy markup no longer carries onclick="" attributes (a CSP with
|
||||
// script-src 'unsafe-inline' removed would otherwise let injected inline
|
||||
// script or event handlers run too) — clicks are handled by the single
|
||||
// delegated listener below, keyed off data-page/data-action. Functions are
|
||||
// still exposed on window because SiteApp.tsx reads window.showDemo for the
|
||||
// mailto-link and "Talk to us" wiring it does independently.
|
||||
/* eslint-disable */
|
||||
|
||||
"use strict";
|
||||
@@ -472,14 +476,37 @@ function initCountUp() {
|
||||
});
|
||||
}
|
||||
|
||||
// ── Click delegation ─────────────────────────────────────────────────────────
|
||||
// Replaces the onclick="" attributes the legacy markup used to carry. A single
|
||||
// document-level listener means none of this depends on script-src 'unsafe-inline'.
|
||||
var ACTIONS = {
|
||||
"close-demo": function () { closeDemo(); },
|
||||
"close-demo-p9": function () { closeDemo(); go("p9"); },
|
||||
"show-demo": function () { showDemo(); },
|
||||
"toggle-mob": function () { toggleMob(); },
|
||||
"submit-demo": function () { submitDemo(); },
|
||||
"submit-contact": function () { submitContact(); },
|
||||
"scroll-down": function () { scrollDown(); },
|
||||
"go-home": function () { goHome(); },
|
||||
// Mirrors the original onclick="closeBg(event)" on the overlay itself: only
|
||||
// fires when the click landed on the overlay, not a descendant (the modal box).
|
||||
"close-bg": function (e, el) { if (e.target === el) closeDemo(); },
|
||||
};
|
||||
|
||||
function handleSiteClick(e) {
|
||||
goPage(e);
|
||||
var el = e.target.closest("[data-action]");
|
||||
if (!el) return;
|
||||
var run = ACTIONS[el.dataset.action];
|
||||
if (run) run(e, el);
|
||||
}
|
||||
|
||||
// ── Init ───────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
// ── Expose globals for inline handlers ─────────────────────────────────────
|
||||
// window.showDemo is the one function SiteApp.tsx still reaches for directly
|
||||
// (mailto-link interception, and the "Talk to us" CTAs it wires independently).
|
||||
var __w = /** @type {any} */ (window);
|
||||
__w.go = go; __w.goPage = goPage; __w.goHome = goHome; __w.toggleMob = toggleMob;
|
||||
__w.scrollDown = scrollDown; __w.showDemo = showDemo; __w.closeDemo = closeDemo;
|
||||
__w.closeBg = closeBg; __w.submitDemo = submitDemo; __w.submitContact = submitContact;
|
||||
__w.showDemo = showDemo;
|
||||
|
||||
var __bdFeedTimer = null;
|
||||
|
||||
@@ -494,6 +521,7 @@ export function initSite(startPage) {
|
||||
window.addEventListener('scroll', hideHint);
|
||||
}
|
||||
window.addEventListener('scroll', onScroll, { passive: true });
|
||||
document.addEventListener('click', handleSiteClick);
|
||||
if (__bdFeedTimer) clearInterval(__bdFeedTimer);
|
||||
__bdFeedTimer = setInterval(cycleFeed, 3400);
|
||||
initCountUp();
|
||||
@@ -501,6 +529,7 @@ export function initSite(startPage) {
|
||||
|
||||
export function teardownSite() {
|
||||
window.removeEventListener('scroll', onScroll);
|
||||
document.removeEventListener('click', handleSiteClick);
|
||||
if (__bdFeedTimer) { clearInterval(__bdFeedTimer); __bdFeedTimer = null; }
|
||||
document.removeEventListener('keydown', __bdModalKeydown, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user