fix(demo): fail closed if synthetic demo data would reach live production#378
Merged
Conversation
…uction Structural guard so the /api/search/universal leak class cannot recur: demoSearch() — the single choke point for synthetic document search (demoAnswer routes through it too) — now throws in a production request unless NEXT_PUBLIC_DEMO_MODE=true. In production the Supabase-config demo fallback and isLocalNoAuthMode are already disabled, so an explicit demo deploy is the only legitimate case. The guard reads process.env directly (not isDemoMode) so it cannot be silently disabled by a test that mocks @/lib/env, and so every current and future caller is covered — not just the routes audited today. Adds 2 regression tests (throws in production; allowed under explicit demo mode). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
BigSimmo
enabled auto-merge (squash)
July 8, 2026 06:56
3 tasks
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
Follow-up hardening to #373 (which stopped
/api/search/universalserving demo docs to live public users). #373 fixed the one route; this closes the whole demo-served-live class so it can't recur through a new route.demoSearch()— the single choke point for synthetic document search (demoAnswerroutes through it too) — now fails closed: it throws in a production request unlessNEXT_PUBLIC_DEMO_MODE=true. In production the Supabase-config demo fallback (nonProductionSupabaseDemoFallbackReasonreturnsnull) andisLocalNoAuthModeare already disabled, so an explicit demo deploy is the only legitimate case.Key design point: the guard reads
process.envdirectly (notisDemoMode) so it cannot be silently disabled by a test that mocks@/lib/env, and so every current and future caller is covered — a new route that hard-codesdemo:true(the exact #373 mistake) would now surface a loud 500 instead of quietly serving fabricated clinical documents. Mirrors the existing fail-closedrequireOwnerScoperetrieval guard.Verification
npx tsc --noEmit— cleannpx eslint+npx prettier --checkon changed files — cleannpx vitest runacross demo/answer/access suites (demo-data,private-access-routes,private-rag-access,public-access-deep,setup-status-route,supabase-errors,owner-scope,api-rate-limit-fallback,rag-answer-fallback,rag-offline-answer,universal-search) — all green, incl. the non-production Supabase-failure fallback paths (guard is inert outside production)npm run verify:cheap/check:production-readiness— not run here (partialnode_modules, no live keys); CI + a maintainer with live keys should run theseClinical Governance Preflight
Notes
demoSearchthrows in a production request; still serves fixtures under an explicitNEXT_PUBLIC_DEMO_MODE=truedeploy.🤖 Generated with Claude Code