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
+23
View File
@@ -219,3 +219,26 @@ describe('cookie table', () => {
])
})
})
describe('forms access', () => {
test('anonymous REST read of a form hides its e-mail recipients; submissions are staff-only', async () => {
await payload.update({
id: formId,
collection: 'forms' as never,
data: { emails: [{ emailTo: '[email protected]', subject: 'Nowe zgłoszenie' }] } as never,
})
const anon = (await payload.findByID({ id: formId, collection: 'forms' as never, overrideAccess: false })) as Record<string, unknown>
expect(anon.fields).toBeDefined()
expect(JSON.stringify(anon.emails ?? [])).not.toContain('[email protected]')
const user = (await payload.create({
collection: 'users',
data: { email: '[email protected]', password: 'Passw0rd!x' } as never,
})) as unknown as Record<string, unknown>
await expect(
payload.find({ collection: 'form-submissions' as never, overrideAccess: false, user: { ...user, collection: 'users' } as never }),
).rejects.toThrow()
const editor = { ...user, collection: 'users', roles: ['editor'] }
expect((await payload.find({ collection: 'form-submissions' as never, overrideAccess: false, user: editor as never })).totalDocs).toBeGreaterThan(0)
})
})