Skip to content

fix(trustlab): address security review leads from #1588 - #1589

Merged
koechkevin merged 9 commits into
mainfrom
fix/trustlab-security-leads
Nov 12, 2026
Merged

koechkevin merged 9 commits into
mainfrom
fix/trustlab-security-leads

Conversation

@koechkevin

@koechkevin koechkevin commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Addresses the three leads from the TrustLab security review in #1588, plus follow-ups from review.

  1. Unpublished pages and posts were publicly readable, including through relationships. Pages and Posts enable drafts but used read: anyone. The site's readers go through the local API, which overrides access by default, populated relationships included.
    • Anonymous reads only see published documents (hasLoggedInOrPublishedAccess, following roboshield's isAdminOrPublished). CMS users still see everything.
    • Public reads through src/lib/payload now set overrideAccess: false, so that rule also applies to populated relationships. An unpublished post in Spotlight/PostList, or a post's draft parent page, comes back as an ID instead of a document. Draft reads (draft: true), which only the authenticated /preview makes, keep overriding access.
    • Tags had no access rules, so they defaulted to logged-in only; anyone can now read them. Spotlight skips unpopulated posts, and PostList accepts IDs as well as documents.
  2. Embed code could render as raw HTML. AirtableEmbed now renders only an iframe whose src is an https URL, with no dangerouslySetInnerHTML fallback. ActionBanner, HelplineCard and RowCard fall back to their link when the embed code doesn't qualify. The iframe is sandboxed (scripts, same-origin, forms, popups) so it can't navigate the page, and its referrer is limited to the site's origin (strict-origin).
  3. Revalidation failed open when REVALIDATE_SECRET was unset. It now returns 401 when no secret is configured. The secret is compared in constant time (SHA-256 digests with timingSafeEqual) and is only accepted as a bearer token, not ?secret=. The CMS hook and scripts/revalidate.mjs already use the bearer header.

Refs #1588.

Validation

Lead 1 was checked against Payload 3.90 with dummy records in a throwaway MongoDB, using the branch's wrapper and access rules. All 11 checks pass:

  • Anonymous page/post lists and lookups return published documents only.
  • A published page's props contain no draft content.
  • Draft relations (Spotlight, PostList, post parent) are IDs.
  • Tags are populated.
  • Preview (draft: true) and CMS users still see drafts.

The same checks run against main's wrapper fail, listing drafts and populating draft posts and parent pages. This confirms the lead.

Leads 2 and 3 are covered by unit tests, and the revalidation tests fail against the old handler. They weren't tested in a browser.

Before deploying

  • Drafts go private. Any page or post that's been live but has status draft in Payload (never published) will return 404 to visitors. Filter Pages and Posts by status in the CMS and publish anything that should stay public.
  • Some embeds stop rendering. ActionBanner/Helpline embed code that isn't an https iframe falls back to the button link.
  • Check an Airtable form on dev. Open, fill and submit a form under the new sandbox, including any post-submission redirect.
  • Check revalidation callers. Any external caller that passed ?secret= must switch to Authorization: Bearer.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected): draft documents and non-iframe embeds are no longer public, and the revalidation secret is no longer accepted in the query string
  • This change requires a documentation update

Screenshots

home-banner home-embed-dialog

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Tested: apps/trustlab Jest (65 suites, 196 tests), eslint and oxfmt on all changed files, plus the Payload validation above. The src/lib/payload wrapper has no unit test: Jest can't transform its top-level await, which is why the existing tests mock it. Not yet run: a build.

Pages and Posts enable drafts but let anyone read them, and the site's
own readers use the local API, which bypasses access control. A
never-published or unpublished document could therefore be read through
the REST/GraphQL API and rendered on the public site.

Anonymous reads now only see published documents, and the local API
wrapper adds the same restriction for collections with drafts unless a
draft read is requested (only the authenticated preview does that).

Refs #1588
With REVALIDATE_SECRET unset, a request without a token compared
undefined with undefined and was allowed to revalidate.

Refs #1588
Authors can add ActionBanner embed code to posts, and embed code without
a parseable iframe src was injected as raw HTML on the public site.

Embeds now render only as an iframe whose src is an https URL. Buttons
whose embed code doesn't qualify fall back to their link instead of
opening an empty dialog.

Refs #1588
@koechkevin koechkevin self-assigned this Nov 10, 2026
@koechkevin
koechkevin marked this pull request as ready for review November 10, 2026 05:59
@koechkevin

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Claude finished @koechkevin's task in 24s —— View job


Review of #1589

The fixes are sound and the tests cover the new behaviour. I read the diff and the surrounding code but did not run the tests or a build. I found no blockers, only the points below.

1. Draft leak (published-only reads)

  • The wrapper in src/lib/payload/index.js filters on _status for any collection with drafts enabled. It skips the filter only when draft: true, and lib/data/common/index.js:98 passes draftMode through. /preview only calls draft.enable() after isAuthor, so anonymous users can't turn it on.
  • hasLoggedInOrPublishedAccess covers the REST and GraphQL paths, which the wrapper doesn't.
  • Relationship fields (not addressed). The local API runs with overrideAccess: true by default, and that applies to populated relationships too. If a published page has a relationship to a draft page or post (for example parent, breadcrumbs, or block references) and the query uses depth > 0, the draft's data can still come back in the page props. The where filter only applies to the top-level query. Check whether any block or collection relationships point at pages or posts, and whether the readers use depth > 0. If they do, either set overrideAccess: false on these reads or strip unpublished relations.
  • Unpublished changes to a live doc. Filtering on _status: published without draft: true reads the main document, which holds the last published content. Edits that aren't published yet stay hidden, which is correct.
  • Minor. payload.collections[collection]?.config?.versions?.drafts returns undefined for a mistyped collection slug, so the filter is silently skipped. This is fine today because the callers are internal, but a short comment or a throw would be safer.

2. Embed (getEmbedSrc)

  • Allowing only an https: URL parsed by new URL, with no dangerouslySetInnerHTML, closes the raw HTML hole. \ssrc= won't match data-src.
  • Entities beyond the five decoded ones (such as /) make new URL fail or resolve to non-https, so the code falls back to the link. That is a safe failure.
  • Consider adding sandbox or referrerpolicy to the rendered iframe if Airtable allows it.
  • AirtableEmbed.js still imports useMemo and useState, and both are used, so nothing is left over.

3. Revalidation

  • !expectedSecret || fails closed, as intended. You could use a constant-time comparison (crypto.timingSafeEqual). That is low priority.
  • The req.query.secret fallback still lets the secret appear in URLs and logs. This is pre-existing and not part of this PR.

Deployment note
The "Drafts go private" warning in the description is the important one. If any live page was published and later has its status set back to draft, it will return 404. After deploy, spot-check the home page and key landing pages.

The local API overrides access by default, including for populated
relationships. Filtering the top-level query on `_status` therefore
still let a published page carry an unpublished post's content through
Spotlight or PostList, or a draft parent page through a post.

Public reads now set `overrideAccess: false`, so the published-only rule
on Pages and Posts applies everywhere and unreadable relations come back
as IDs. Draft reads, which only the authenticated preview makes, keep
overriding access. This replaces the `publishedOnly` helper.

Tags had no access rules, so anonymous visitors couldn't read them under
Payload's default; they're public now. Spotlight skips posts that
weren't populated, and PostList accepts IDs as well as documents.

Validated against Payload 3 with dummy records in a throwaway database:
anonymous reads list only published pages and posts, unpublished
relations are IDs, and preview and CMS users still see drafts. The same
checks fail on main.

Refs #1588
Compare the secret's digest in constant time, and stop reading it from
the query string, where it ends up in URLs and logs. The CMS and the
deploy script both send it as a bearer token.

Refs #1588
Embedded iframes can no longer navigate the page, start downloads or
open modal dialogs, and only receive the site's origin as referrer.
Forms keep scripts, submissions and popups.

Also regenerate payload-types.ts for the embed code descriptions.

Refs #1588
@koechkevin
koechkevin requested a review from a team November 10, 2026 09:06

@kilemensi kilemensi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏾 ... Can we include screenshots of how the new embed works/looks like?

Spotlight skipped relationship items that Payload left as IDs. Query the
selected posts instead, as PostList does, so the posts read access
decides which are shown. This also replaces a query per item with one.
@koechkevin
koechkevin requested a review from kilemensi November 10, 2026 13:24
@kilemensi

Copy link
Copy Markdown
Member

Could we simplify Spotlight by using the posts already populated by the page query?

With overrideAccess: false, Payload enforces the posts’ read access and leaves inaccessible references as IDs. We could filter out those ID-only entries and build cards from the populated objects, avoiding the second query and preserving the original order, card overrides and preview content.

My understanding is that depth 2 should populate the required image, tags and parent, and that collection afterRead hooks also run for populated posts, supplying their computed links. Could we confirm that with an integration test covering public reads and authenticated preview, and make the required depth explicit?

Also, could we apply overrideAccess: false to public findGlobal() reads? Otherwise, navigation relationships in site settings can still populate unpublished pages.

Query the spotlight posts with the preview's draft mode, so that
preview shows the draft posts. The posts are queried rather than taken
from the page because posts reached through a relationship don't get
their parent page (maxDepth: 1), so their links can't be built.
Navigation links in the site settings populated unpublished pages.

@kilemensi kilemensi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM... not in a position to run it locally though.

@koechkevin
koechkevin added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit befc66e Nov 12, 2026
13 checks passed
@koechkevin
koechkevin deleted the fix/trustlab-security-leads branch November 12, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants