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:
2026-10-16 03:06:26 +02:00
co-authored by Claude Opus 5.5
parent ebf70d49bd
commit 9e49856611
14 changed files with 284 additions and 20 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
export { buildLinkField, buildLinksField } from './buildLinkField.js'
export type { BuildLinkFieldOptions, BuildLinksFieldOptions, LinkAppearance } from './buildLinkField.js'
export { resolveLinkHref } from './resolveLinkHref.js'
export { resolveLinkHref, safeHref } from './resolveLinkHref.js'
export type { LinkValue, ResolveLinkHrefOptions } from './resolveLinkHref.js'
+16 -1
View File
@@ -6,6 +6,21 @@ import { buildLocalizedPath } from '../i18n/index.js'
* Minimal shape of a link value (the project's generated `CmsLink` fits it).
* The plugin doesn't know the project's types — only this contract.
*/
/**
* Schemes a CMS link may use. The field validates this too, but data can come
* from imports, seeds or older versions — `javascript:`, `data:` and other
* schemes are dropped here so a stored link can never run script on click.
*/
const SAFE_HREF = /^(?:https?:\/\/|mailto:|tel:|sms:|#|\/(?!\/))/i
/** The URL when it's a safe link target, otherwise null (control characters — e.g. "java\tscript:" — reject it). */
export function safeHref(url: null | string | undefined): null | string {
const v = url?.trim()
// eslint-disable-next-line no-control-regex
if (!v || /[\u0000-\u001F\u007F]/.test(v)) {return null}
return SAFE_HREF.test(v) ? v : null
}
export type LinkValue = {
appearance?: null | string
file?: unknown
@@ -43,7 +58,7 @@ export function resolveLinkHref(
): null | string {
if (!link) {return null}
if (link.type === 'external') {return link.url?.trim() || null}
if (link.type === 'external') {return safeHref(link.url)}
if (link.type === 'file') {
const file = link.file