Repository navigation
fix(access)!: a client key reads draft globals with ?draft=true, and #777 made them cacheable - #785
Merged
Merged
Conversation
…777 made them cacheable `createAccessConfig` constrains a client read of a draft-enabled entity to `{ _status: { equals: 'published' } }` unless the request carries a valid preview secret. That clause asked `collectionHasDrafts`, which resolved the slug through `req.payload.collections[...]` — a map a global is not in. So it answered `false` for every global, the clause never fired on one, and an ordinary client API key plus `?draft=true` read unpublished copy out of all three translations globals with no preview secret at all. #777 raised the stakes. `/api/globals/<slug>` is now edge-cacheable, and `matchCacheableRead` keys on the pathname while the middleware gates `no-store` on the preview-secret *header*. So the same uncredentialed draft read came back `public, max-age=600, s-maxage=600` and could sit at the Cloudflare edge for ten minutes, replayed by `Vary: Authorization` to every request sharing that API key — which, for WeMeditateWeb, is every visitor. Two independent fixes, because the two layers answer different questions: - `entityHasDrafts` checks `req.payload.config.globals` as well as collections, so the published-only clause fires on a global. This is the access fix. - `isDraftRead` marks any read carrying a truthy `?draft=` as unstorable, whether or not a preview secret rides with it. A caller may be legitimately authorised for drafts and the response still must not enter a shared cache. Applied on both cache surfaces — the REST middleware and the in-handler decorator. `draft=false`, `draft=0` and `draft=` stay cacheable: WeMeditateWeb passes `draft: isPreview` unconditionally, so treating the parameter's presence as a draft read would make the whole site uncacheable. An unrecognised value fails closed. Both halves were watched failing first — the integration cases returned the unpublished string, and the cache cases returned `public, max-age=600`. DEPLOYMENT.md records the recommended Cache Rule hardening: the rule already excludes the preview-secret header, and should exclude `draft=true` too, so the bypass does not rest on an origin header alone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-785
September 15, 2026 01:25
Destroyed
|
🚅 Deployed to the SahajCloud-pr-785 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
pushed a commit
that referenced
this pull request
Sep 15, 2026
One conflict, in docs/rules/access.md, additive on both sides. This branch rewrote the API-client paragraph for the #723 grants: `user-submissions` create for `wemeditate-web` and `sahaj-atlas`, and the removal of `registrations: ['update']`. `main` (#785) appended "and globals" to the published-only clause and added the warning paragraph explaining why that clause is load-bearing. Both are kept: this branch's paragraph carries `main`'s "and globals", and `main`'s warning follows it. Neither side's rule is dropped. `main` renamed `collectionHasDrafts` to `entityHasDrafts` in src/plugins/access/accessConfigs.ts; that merged cleanly and this branch has no other caller. `main` brought no migration, so the snapshot chain is untouched. Gate at this merge: lint, tsc over src/ and tests/, unit lane (2045 tests, 143 files). Targeted specs — globals-client-reads, pages, user-submissions-access, user-submissions-create: 4 files / 67 tests, green. Snapshot probe `db:migrations:create --skip-empty` exits 0 and writes no files. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CRPiPGyw3GbouYVZwkKihG
This was referenced Sep 17, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
?draft=trueread unpublished copy out of all three translations globals, with no preview secret. Reproduced, not inferred.public, max-age=600, s-maxage=600, storable at the Cloudflare edge and replayed byVary: Authorizationto every request sharing the API key — for WeMeditateWeb, every visitor.The defect
createAccessConfigconstrains a client read of a draft-enabled entity to{ _status: { equals: 'published' } }unless the request carries a valid preview secret. That clause askedcollectionHasDrafts, which resolved the slug throughreq.payload.collections[...]— a map a global is not in. It answeredfalsefor every global, so the clause never fired on one.All three translations globals declare
versions.drafts, so the gate mattered and was absent.Then #777 made
/api/globals/<slug>edge-cacheable.matchCacheableReadkeys on the pathname, andmiddleware.tsgatesno-storeon the preview-secret header — neither looks atdraft. So the draft read was not merely served, it was storable.Changes
src/plugins/access/accessConfigs.ts—collectionHasDrafts→entityHasDrafts, which also checksreq.payload.config.globals. This is the access fix.src/plugins/cache/policy.ts— newisDraftRead, andbuildCacheHeadersreturnsprivate, no-storefor a draft read as well as a preview one. A caller may be legitimately authorised for drafts and the response still must not enter a shared cache.src/plugins/cache/middleware.ts,src/plugins/cache/cacheHeaders.ts— both cache surfaces pass it, so they stay byte-identical.DEPLOYMENT.md,docs/rules/access.md— record both, and the recommended Cache Rule hardening.draft=falsestays cacheable, deliberatelyWeMeditateWeb passes
draft: isPreviewunconditionally, so every ordinary read serialisesdraft=false. Treating the parameter's presence as a draft read would make the whole site uncacheable.'',falseand0are non-draft; anything else — including an unrecognised value — fails closed.Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(2017 → 2023 unit tests) — all greenglobals-client-reads,role-based-access,client-query-validation(109 passed);translations-globals,pages-localize-status,atlas-collections(56 passed)Both halves watched failing first, as
docs/rules/testing-reqs.mdrequires:Notes for reviewer
The Cache Rule is "Respect origin", so the app-layer
private, no-storeis sufficient on its own — this is not waiting on a dashboard change. ButDEPLOYMENT.mdnow recommends addingnot http.request.uri.query contains "draft=true"to the rule, mirroring the preview-secret exclusion already there, so the bypass does not rest on a single origin header.Marked
!because a client sending?draft=trueagainst a global previously got drafts and now gets published content. That is the fix, not a regression, but it is a behaviour change on a live API.Found while planning the cross-repo live-preview unification — the work that supersedes #776. It is fixed here rather than there because it is live, independent, and shipping it should not wait.
🤖 Generated with Claude Code