Security review: drafts no longer public, submissions staff-only, safe links, upload sandbox
- Fix: resolveRoute served never-published drafts by URL (Payload's find returns them with _status 'draft') — also via Markdown, MCP get_page and metadata. Drafts are dropped on every branch; `draft: true` for previews. - Fix: getArchiveEntries listed drafts in archive pages despite its comment; `_status: published` is added automatically when the collection has drafts. - form-submissions readable only by editor+ (form-builder default: any account of the admin collection, incl. plain users from an open sign-up); delete admin. - Forms stay public for rendering, but the Emails tab (recipients) is hidden from anonymous REST reads. - safeHref: CMS links only http(s), mailto, tel, sms, #, / — javascript:, data: and control-character tricks are dropped in resolveLinkHref. - Analytics IDs validated in the panel and before reaching the browser. - buildUploadSecurityHeaders: sandbox CSP for /api/<upload>/file/* so an uploaded SVG can't run script on the site's origin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -125,3 +125,30 @@ export function buildSecurityHeaders(args: BuildSecurityHeadersArgs = {}): Secur
|
||||
|
||||
return headers
|
||||
}
|
||||
|
||||
/**
|
||||
* Headers for files served from the upload routes. Media accept `image/*`,
|
||||
* which includes SVG — and an SVG opened directly from the site's own origin
|
||||
* can run script (stored XSS from any account that can upload). This CSP lets
|
||||
* the file display but never execute: no scripts, no plugins, sandboxed.
|
||||
* Media on R2 come from another domain and are already isolated; local-disk
|
||||
* media (dev, or sites without R2) need this.
|
||||
*
|
||||
* // next.config.ts — next to the site-wide headers
|
||||
* async headers() {
|
||||
* return [
|
||||
* { source: '/:path*', headers: securityHeaders },
|
||||
* ...buildUploadSecurityHeaders(), // default: /api/media/file/*
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
export function buildUploadSecurityHeaders({ collections = ['media'] }: { collections?: string[] } = {}): {
|
||||
headers: SecurityHeader[]
|
||||
source: string
|
||||
}[] {
|
||||
const headers: SecurityHeader[] = [
|
||||
{ key: 'Content-Security-Policy', value: "default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'; sandbox" },
|
||||
{ key: 'X-Content-Type-Options', value: 'nosniff' },
|
||||
]
|
||||
return collections.map((slug) => ({ headers, source: `/api/${slug}/file/:path*` }))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { buildCsp } from './buildCsp.js'
|
||||
export type { BuildCspArgs } from './buildCsp.js'
|
||||
export { buildSecurityHeaders } from './buildSecurityHeaders.js'
|
||||
export { buildSecurityHeaders, buildUploadSecurityHeaders } from './buildSecurityHeaders.js'
|
||||
export type { BuildSecurityHeadersArgs, SecurityHeader, } from './buildSecurityHeaders.js'
|
||||
|
||||
Reference in New Issue
Block a user