Files
Radosław SmolińskiandClaude Fable 5.2 9143c132a3 Payload's colour-scheme client hints go to the admin only: withSecurityConfig outside withPayload
withPayload adds Accept-CH, Critical-CH and Vary: Sec-CH-Prefers-Color-Scheme for /:path*; Critical-CH makes
Chrome repeat the first document request of a visit to a public page. As the outer wrapper, withSecurityConfig
moves the three headers to /admin/:path* (adminClientHints: { route, sources } | false). Inside withPayload
nothing changes, so an unedited site behaves as before. Exports scopeColorSchemeClientHints,
adminClientHintSources, COLOR_SCHEME_CLIENT_HINT; doctor rule client-hints (info); reference site and starter
use the new order; e2e:built and the starter gate check it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-26 11:55:26 +01:00

63 lines
2.4 KiB
TypeScript

import type { NextConfig } from 'next'
import {
buildAdminCspHeaders,
buildImagesConfig,
buildSecurityHeaders,
buildUploadSecurityHeaders,
withSecurityConfig,
} from '@intecion/ipal-kit'
import { withPayload } from '@payloadcms/next/withPayload'
// @starter:if enforceCsp
// CSP enforced: the reference site is the example after the report-only phase (security.md → "ROLL OUT CSP").
const csp = { mode: 'enforce', r2Url: process.env.R2_PUBLIC_URL, reportUri: '/api/csp-report' } as const
// @starter:else
//: // CSP step 1: report-only. Read the [csp] lines in the logs, add a flag or `extra` per report, then switch to
//: // mode: 'enforce' (security.md → "ROLL OUT CSP"; iapl-doctor.json silences the report-only finding until then).
//: const csp = { mode: 'report-only', r2Url: process.env.R2_PUBLIC_URL, reportUri: '/api/csp-report' } as const
// @starter:endif
// Flags = what the site loads: Turnstile on forms, the analytics tools whose IDs are set in Site integrations.
const securityHeaders = buildSecurityHeaders({
csp: {
...csp,
// @starter:if analytics
analytics: true,
// @starter:endif
// @starter:if metaPixel
//: metaPixel: true,
// @starter:endif
// @starter:if linkedIn
//: linkedIn: true,
// @starter:endif
// @starter:if tiktok
//: tiktok: true,
// @starter:endif
// @starter:if clarity
//: clarity: true,
// @starter:endif
turnstile: true,
},
hsts: process.env.NODE_ENV === 'production',
})
const nextConfig: NextConfig = {
// ALLOW_LOCAL_MEDIA=1 (local / CI production checks only): let next/image optimize files the app serves on localhost
images: buildImagesConfig(process.env.ALLOW_LOCAL_MEDIA === '1' ? { production: false } : {}),
// Metadata in <head> for crawlers (deployment.md §3a)
htmlLimitedBots:
/Googlebot|Google-InspectionTool|Storebot-Google|Bingbot|Yandex|DuckDuckBot|Baiduspider|Screaming Frog|AhrefsBot|SemrushBot/i,
async headers() {
return [
{ source: '/:path*', headers: securityHeaders },
{ source: '/admin/:path*', headers: buildAdminCspHeaders(csp) }, // after the site-wide rule
...buildUploadSecurityHeaders(),
]
},
}
// withSecurityConfig OUTSIDE withPayload: no X-Powered-By (Next's and Payload's), and Payload's colour-scheme
// client hints (Accept-CH, Critical-CH, Vary) for /admin only, so a public page is requested once (security.md)
export default withSecurityConfig(withPayload(nextConfig))