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:
@@ -15,6 +15,8 @@ type GetArchiveEntriesArgs = {
|
||||
collection: string
|
||||
/** Relationship depth. Defaults to 1 — enough for a cover image. */
|
||||
depth?: number
|
||||
/** Preview (draftMode): include unpublished entries and latest drafts. Default false. */
|
||||
draft?: boolean
|
||||
locale: string
|
||||
/** 1-based. Values below 1 are clamped. */
|
||||
page?: number
|
||||
@@ -30,9 +32,10 @@ type GetArchiveEntriesArgs = {
|
||||
/**
|
||||
* Fetches one page of a collection's entries for an archive listing.
|
||||
*
|
||||
* Only published documents are returned when the collection has drafts enabled;
|
||||
* Payload's `where` on `_status` is left to the caller, since a collection
|
||||
* without drafts has no such field.
|
||||
* Only published documents are returned when the collection has drafts enabled
|
||||
* (the `_status` filter is added automatically — only then, since a collection
|
||||
* without drafts has no such field and querying it would throw). Pass
|
||||
* `draft: true` for a preview.
|
||||
*
|
||||
* Returns pagination facts rather than markup — the listing itself belongs to
|
||||
* the client (as a block on the archive page, most likely), because how a list
|
||||
@@ -41,6 +44,7 @@ type GetArchiveEntriesArgs = {
|
||||
export async function getArchiveEntries<T = Record<string, unknown>>({
|
||||
collection,
|
||||
depth = 1,
|
||||
draft = false,
|
||||
locale,
|
||||
page = 1,
|
||||
payload,
|
||||
@@ -48,14 +52,20 @@ export async function getArchiveEntries<T = Record<string, unknown>>({
|
||||
sort = '-createdAt',
|
||||
where,
|
||||
}: GetArchiveEntriesArgs): Promise<ArchiveEntries<T>> {
|
||||
const versions = payload.collections?.[collection as never]?.config?.versions as { drafts?: unknown } | false | undefined
|
||||
const hasDrafts = Boolean(versions && versions.drafts)
|
||||
const published = !draft && hasDrafts ? { _status: { equals: 'published' } } : undefined
|
||||
const fullWhere = published && where ? { and: [published, where] } : (published ?? where)
|
||||
|
||||
const result = await payload.find({
|
||||
collection: collection as never,
|
||||
depth,
|
||||
draft,
|
||||
limit: perPage,
|
||||
locale: locale as never,
|
||||
page: Math.max(1, page),
|
||||
sort,
|
||||
...(where ? { where: where as never } : {}),
|
||||
...(fullWhere ? { where: fullWhere as never } : {}),
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user