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:
@@ -31,6 +31,12 @@ export type ResolvedRoute =
|
||||
|
||||
type ResolveRouteArgs = {
|
||||
content?: ContentOption
|
||||
/**
|
||||
* Preview (Next draftMode): return the latest draft instead of the published
|
||||
* version, and resolve never-published pages. Default false — public
|
||||
* requests only ever see published content.
|
||||
*/
|
||||
draft?: boolean
|
||||
locale: string
|
||||
/** Page number from the query string (?page=2). Defaults to 1. */
|
||||
page?: number
|
||||
@@ -72,8 +78,20 @@ type ResolveRouteArgs = {
|
||||
* make canonical and hreflang ambiguous (the same entry reachable under several
|
||||
* URLs).
|
||||
*/
|
||||
/**
|
||||
* Payload's `find` returns never-published documents from the main collection
|
||||
* (with `_status: 'draft'`) unless asked otherwise — public routing must drop
|
||||
* them, or an unpublished page is reachable by its URL.
|
||||
*/
|
||||
function isPublic(doc: unknown, draft: boolean): boolean {
|
||||
if (draft || !doc || typeof doc !== 'object') {return Boolean(doc)}
|
||||
const status = (doc as { _status?: unknown })._status
|
||||
return status === undefined || status === null || status === 'published'
|
||||
}
|
||||
|
||||
export async function resolveRoute({
|
||||
content,
|
||||
draft = false,
|
||||
locale,
|
||||
page = 1,
|
||||
pagesSlug = 'pages',
|
||||
@@ -107,10 +125,11 @@ export async function resolveRoute({
|
||||
id: homepageId,
|
||||
collection: pagesSlug,
|
||||
depth: 2,
|
||||
draft,
|
||||
locale: locale as never,
|
||||
})
|
||||
|
||||
return doc ? { type: 'home', doc: doc as Record<string, unknown> } : null
|
||||
return doc && isPublic(doc, draft) ? { type: 'home', doc: doc as Record<string, unknown> } : null
|
||||
}
|
||||
|
||||
const [first, ...rest] = segments
|
||||
@@ -122,6 +141,7 @@ export async function resolveRoute({
|
||||
|
||||
const archiveDoc = archive as ArchivePage
|
||||
if (archiveDoc.slug !== first) {continue}
|
||||
if (!isPublic(archiveDoc, draft)) {return null}
|
||||
|
||||
// /pl/artykuly → the archive page itself.
|
||||
if (rest.length === 0) {
|
||||
@@ -139,12 +159,13 @@ export async function resolveRoute({
|
||||
const found = await payload.find({
|
||||
collection: collection.slug as never,
|
||||
depth: 2,
|
||||
draft,
|
||||
limit: 1,
|
||||
locale: locale as never,
|
||||
where: { slug: { equals: rest[0] } },
|
||||
})
|
||||
const entry = found.docs[0]
|
||||
if (!entry) {return null}
|
||||
if (!entry || !isPublic(entry, draft)) {return null}
|
||||
|
||||
return {
|
||||
type: 'entry',
|
||||
@@ -162,12 +183,13 @@ export async function resolveRoute({
|
||||
const found = await payload.find({
|
||||
collection: pagesSlug as never,
|
||||
depth: 2,
|
||||
draft,
|
||||
limit: 1,
|
||||
locale: locale as never,
|
||||
where: { slug: { equals: segments.join('/') } },
|
||||
})
|
||||
const doc = found.docs[0]
|
||||
if (!doc) {return null}
|
||||
if (!doc || !isPublic(doc, draft)) {return null}
|
||||
|
||||
// The page assigned as 404 in System Pages must not be reachable as a normal
|
||||
// 200 URL (/pl/strona-nie-znaleziona) — that's a soft-404 / duplicate. Treat
|
||||
|
||||
Reference in New Issue
Block a user