Enforce CSP without unsafe-inline, and close out the remaining retest items
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:
2026-08-20 21:02:53 +05:00
co-authored by Claude Sonnet 5
parent 2baac6eab4
commit 11a709744e
5 changed files with 134 additions and 91 deletions
+14 -6
View File
@@ -162,13 +162,15 @@ setInterval(() => {
}, THROTTLE_WINDOW_MS).unref()
// ── Helpers ────────────────────────────────────────────────────────────────────
// CSP ships in report-only mode: the legacy markup relies on inline onclick=""
// handlers, so enforcing script-src today would break navigation. Report-only
// costs nothing (it can't break the site) and surfaces exactly what a real
// policy needs to allow before anyone flips it to enforcing.
// script-src has no 'unsafe-inline': the legacy markup's onclick="" attributes
// were migrated to a single delegated listener (siteController.js), and no
// inline <script> exists anywhere in the app, so there's nothing left for it to
// allow. style-src keeps 'unsafe-inline' — React's style prop and the legacy
// markup's inline style="" attributes are load-bearing throughout and out of
// scope here; that's a CSS-injection concern, not the XSS one this closes.
const CSP = [
"default-src 'self'",
"script-src 'self' 'unsafe-inline' https://*.hubspot.com https://*.hs-scripts.com https://*.hsforms.net https://*.usemessages.com",
"script-src 'self' https://*.hubspot.com https://*.hs-scripts.com https://*.hsforms.net https://*.usemessages.com",
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com",
"font-src 'self' https://fonts.gstatic.com",
"img-src 'self' data: https:",
@@ -185,7 +187,7 @@ const SECURITY_HEADERS = {
'X-Frame-Options': 'SAMEORIGIN',
'Referrer-Policy': 'strict-origin-when-cross-origin',
'Permissions-Policy': 'geolocation=(), camera=(), microphone=()',
'Content-Security-Policy-Report-Only': CSP,
'Content-Security-Policy': CSP,
// Harmless (and ignored) over plain HTTP; takes effect once a browser sees it over TLS.
'Strict-Transport-Security': 'max-age=63072000; includeSubDomains',
}
@@ -268,6 +270,10 @@ async function serveFile(req, res, file, { immutable = false } = {}) {
}
const type = MIME[path.extname(file).toLowerCase()] || 'application/octet-stream'
const cache = immutable ? 'public, max-age=31536000, immutable' : 'public, max-age=300'
// Uploaded PDFs are served from the site's own origin with no sandboxing.
// Forcing a download rather than inline rendering keeps a crafted PDF from
// being used as a same-origin phishing page.
const disposition = type === 'application/pdf' ? { 'Content-Disposition': `attachment; filename="${path.basename(file)}"` } : {}
const range = /^bytes=(\d*)-(\d*)$/.exec(req.headers.range || '')
if (range) {
const start = range[1] ? Number(range[1]) : 0
@@ -278,6 +284,7 @@ async function serveFile(req, res, file, { immutable = false } = {}) {
'Accept-Ranges': 'bytes',
'Content-Length': end - start + 1,
'Cache-Control': cache,
...disposition,
...SECURITY_HEADERS,
})
fs.createReadStream(file, { start, end }).pipe(res)
@@ -288,6 +295,7 @@ async function serveFile(req, res, file, { immutable = false } = {}) {
'Content-Length': stat.size,
'Accept-Ranges': 'bytes',
'Cache-Control': cache,
...disposition,
...SECURITY_HEADERS,
})
fs.createReadStream(file).pipe(res)