Repository navigation
fix(api): exempt live-preview reads from select/populate gate - #428
Merged
Merged
Conversation
The mandatory select/populate gate added in #294 fires for every clients-collection read, including the draft fetch the admin live preview makes via the We Meditate Web frontend. A preview renders the whole document and doesn't enumerate select, so the gate returned 400 and the preview surfaced a 500. Skip the gate when a request carries the valid SAHAJCLOUD_PREVIEW_SECRET header — the same trust signal that already unlocks drafts. Extract the check into a shared hasValidPreviewSecret() helper and reuse it in both the usage hook and the access config. Rate limiting and usage tracking are untouched. Fixes meditations, pages, and wemeditate-web previews. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
The Meditations (and Pages / wemeditate-web) live preview broke with a 500 after #294 / #420 introduced the mandatory
select+populatequery-param gate for API client reads.Root cause: The admin live-preview iframe loads the external We Meditate Web frontend with the shared
SAHAJCLOUD_PREVIEW_SECRET. That frontend fetches the draft document back from this CMS as thewemeditate-webclient, forwarding the secret in thex-sahajcloud-preview-secretheader to unlock drafts. PR #294'svalidateClientQueryParamsHook(beforeOperationon every non-system collection) now rejects that read with 400 because a preview fetch wants the whole document and doesn't enumerateselect/populate. The frontend then surfaces a 500. Payload's built-in preview machinery is fine — only the new gate is the problem.Fix: Skip the
select/populatevalidation when a request carries the valid preview secret — the same trust signal that already unlocks drafts increateAccessConfig. A full-document render can't meaningfully enumerateselect, and the param requirement is a quota/perf guardrail, not a security boundary; preview traffic is low-volume.src/lib/previewSecret.ts—hasValidPreviewSecret(req)+PREVIEW_SECRET_HEADER, a single source of truth for the secret check.validateClientQueryParamsHookearly-returns for valid-preview-secret reads (rate limiting + usage tracking untouched).accessConfigs.tsde-duped to use the shared helper (was an inline header compare)..claude/rules/api-clients.md.Fixes meditations, pages, and the wemeditate-web global preview in one place — no external-frontend change required.
Test plan
pnpm lint— 0 errorspnpm exec vitest run tests/int/client-query-validation.int.spec.ts --config ./vitest.config.mts— 27 passed (3 new: preview-secret bypasses the gate onfind/findByID@Depth=2; a wrong secret is still rejected)🤖 Generated with Claude Code