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:
@@ -3,6 +3,7 @@ import type { BasePayload } from 'payload'
|
||||
import type { AnalyticsConfig } from './types.js'
|
||||
|
||||
import { getSiteIntegrations } from '../payload/index.js'
|
||||
import { validAnalyticsId } from './idFormats.js'
|
||||
|
||||
/**
|
||||
* Reads the public analytics / marketing tag IDs from SiteIntegrations,
|
||||
@@ -12,11 +13,11 @@ import { getSiteIntegrations } from '../payload/index.js'
|
||||
export async function getAnalyticsConfig(payload: BasePayload): Promise<AnalyticsConfig> {
|
||||
const integrations = await getSiteIntegrations<AnalyticsConfig>(payload)
|
||||
return {
|
||||
clarityProjectId: integrations.clarityProjectId ?? null,
|
||||
ga4MeasurementId: integrations.ga4MeasurementId ?? null,
|
||||
gtmContainerId: integrations.gtmContainerId ?? null,
|
||||
linkedInPartnerId: integrations.linkedInPartnerId ?? null,
|
||||
metaPixelId: integrations.metaPixelId ?? null,
|
||||
tiktokPixelId: integrations.tiktokPixelId ?? null,
|
||||
clarityProjectId: validAnalyticsId('clarityProjectId', integrations.clarityProjectId),
|
||||
ga4MeasurementId: validAnalyticsId('ga4MeasurementId', integrations.ga4MeasurementId),
|
||||
gtmContainerId: validAnalyticsId('gtmContainerId', integrations.gtmContainerId),
|
||||
linkedInPartnerId: validAnalyticsId('linkedInPartnerId', integrations.linkedInPartnerId),
|
||||
metaPixelId: validAnalyticsId('metaPixelId', integrations.metaPixelId),
|
||||
tiktokPixelId: validAnalyticsId('tiktokPixelId', integrations.tiktokPixelId),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Formats of the tag IDs typed into Site Integrations. Used twice: as field
|
||||
* validation in the panel (typos caught on save) and when the IDs are handed to
|
||||
* the browser (getAnalyticsConfig) — a malformed value from an import or an old
|
||||
* version is dropped instead of being put into a script URL.
|
||||
*/
|
||||
export const ANALYTICS_ID_FORMATS = {
|
||||
clarityProjectId: /^[a-z0-9]{5,20}$/i,
|
||||
ga4MeasurementId: /^G-[A-Z0-9]{4,20}$/,
|
||||
gtmContainerId: /^GTM-[A-Z0-9]{4,12}$/,
|
||||
linkedInPartnerId: /^\d{3,12}$/,
|
||||
metaPixelId: /^\d{5,20}$/,
|
||||
tiktokPixelId: /^[A-Z0-9]{10,30}$/i,
|
||||
} as const
|
||||
|
||||
export type AnalyticsIdField = keyof typeof ANALYTICS_ID_FORMATS
|
||||
|
||||
/** The trimmed ID when it matches its format, else null. */
|
||||
export function validAnalyticsId(field: AnalyticsIdField, value: unknown): null | string {
|
||||
const v = typeof value === 'string' ? value.trim() : ''
|
||||
return v && ANALYTICS_ID_FORMATS[field].test(v) ? v : null
|
||||
}
|
||||
|
||||
/** Payload field `validate` for an ID field. */
|
||||
export const validateAnalyticsId =
|
||||
(field: AnalyticsIdField, example: string) =>
|
||||
(value: null | string | undefined): string | true =>
|
||||
!value?.trim() || validAnalyticsId(field, value) !== null || `Unexpected format — expected something like ${example}`
|
||||
Reference in New Issue
Block a user