Security: hide X-Powered-By, CSP report-only with reports, admin policy and nonces
- withSecurityConfig: poweredByHeader false + strips X-Powered-By from headers()
(Next's and withPayload's), works on either side of withPayload
- buildSecurityHeaders({ csp }): CSP + Reporting-Endpoints; mode switches
report-only → enforce
- buildCsp: reportUri/reportGroup, nonce + strict-dynamic, dev unsafe-eval,
metaPixel/linkedIn/tiktok/clarity flags, media-src for R2, override
- buildAdminCsp(Headers): looser policy for Payload admin (Monaco CDN, blob workers)
- createCspReportRoute + parseCspReports: report collector for both formats
- createProxy({ csp }) + createCspNonce: per-request nonce, x-nonce header;
SiteProviders/ThemeScript/Analytics/ConsentScript accept nonce
- docs: security.md, AGENT.md, ipal-setup/reference/upgrade; ipal-audit checks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
771dda1c6f
commit
ff4c595b91
@@ -25,6 +25,11 @@ type ConsentScriptProps = {
|
||||
defer?: boolean
|
||||
/** Stable id used to dedupe — the script is injected at most once. */
|
||||
id?: string
|
||||
/**
|
||||
* CSP nonce for both the external and the inline script. Only needed with a
|
||||
* nonce policy WITHOUT 'strict-dynamic' (with it, scripts the app adds are trusted).
|
||||
*/
|
||||
nonce?: string
|
||||
/** External script URL. Injected only once the category is granted. */
|
||||
src?: string
|
||||
}
|
||||
@@ -60,6 +65,7 @@ export function ConsentScript({
|
||||
category,
|
||||
code,
|
||||
defer,
|
||||
nonce,
|
||||
src,
|
||||
}: ConsentScriptProps) {
|
||||
const { state } = useConsentContext()
|
||||
@@ -82,6 +88,7 @@ export function ConsentScript({
|
||||
if (!code) {return}
|
||||
const inline = document.createElement('script')
|
||||
if (dedupeId) {inline.id = `${dedupeId}-inline`}
|
||||
if (nonce) {inline.nonce = nonce}
|
||||
inline.textContent = code
|
||||
document.head.appendChild(inline)
|
||||
}
|
||||
@@ -92,6 +99,7 @@ export function ConsentScript({
|
||||
if (dedupeId) {el.id = dedupeId}
|
||||
if (asyncAttr) {el.async = true}
|
||||
if (defer) {el.defer = true}
|
||||
if (nonce) {el.nonce = nonce}
|
||||
if (attributes) {for (const [k, v] of Object.entries(attributes)) {el.setAttribute(k, v)}}
|
||||
// eslint-disable-next-line @eslint-react/web-api/no-leaked-event-listener -- one-shot, and the script is never unloaded (see below)
|
||||
el.addEventListener('load', runInline, { once: true })
|
||||
@@ -102,7 +110,7 @@ export function ConsentScript({
|
||||
// Deliberately no removal on cleanup: a loaded third-party script can't be
|
||||
// meaningfully unloaded. Withdrawal is handled by not re-injecting (and, for
|
||||
// vendors that support it, Consent Mode). See the component doc.
|
||||
}, [granted, src, code, id, attributes, asyncAttr, defer])
|
||||
}, [granted, src, code, id, attributes, asyncAttr, defer, nonce])
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user