Repository navigation
fix(trustlab): address security review leads from #1588 - #1589
Conversation
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
|
@claude review |
|
Claude finished @koechkevin's task in 24s —— View job Review of #1589The 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)
2. Embed (
3. Revalidation
Deployment note |
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
kilemensi
left a comment
There was a problem hiding this comment.
👍🏾 ... 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.
|
Could we simplify Spotlight by using the posts already populated by the page query? With My understanding is that depth 2 should populate the required image, tags and parent, and that collection Also, could we apply |
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
left a comment
There was a problem hiding this comment.
Code LGTM... not in a position to run it locally though.
Description
Addresses the three leads from the TrustLab security review in #1588, plus follow-ups from review.
read: anyone. The site's readers go through the local API, which overrides access by default, populated relationships included.hasLoggedInOrPublishedAccess, following roboshield'sisAdminOrPublished). CMS users still see everything.src/lib/payloadnow setoverrideAccess: 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/previewmakes, keep overriding access.AirtableEmbednow renders only an iframe whosesrcis anhttpsURL, with nodangerouslySetInnerHTMLfallback. 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).REVALIDATE_SECRETwas unset. It now returns 401 when no secret is configured. The secret is compared in constant time (SHA-256 digests withtimingSafeEqual) and is only accepted as a bearer token, not?secret=. The CMS hook andscripts/revalidate.mjsalready 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:
parent) are IDs.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
httpsiframe falls back to the button link.sandbox, including any post-submission redirect.?secret=must switch toAuthorization: Bearer.Type of change
Screenshots
Checklist:
Tested:
apps/trustlabJest (65 suites, 196 tests), eslint and oxfmt on all changed files, plus the Payload validation above. Thesrc/lib/payloadwrapper has no unit test: Jest can't transform its top-levelawait, which is why the existing tests mock it. Not yet run: a build.