Fix: restore Cloudflare Turnstile client wiring for Google signup gate - #217
Conversation
|
Warning Review limit reached
Next review available in: 27 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR configures Cloudflare Turnstile for builds and browser loading, updates CSP validation, enforces verification failures in authentication, forwards successful tokens, and refines Supabase signup responses and alerts. ChangesTurnstile integration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Preview for Bayan Flow Staging ready!
Preview alias |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/services/authService.test.js`:
- Around line 153-175: Add a fake-timer test alongside the existing Turnstile
failure tests in the authService test suite, configuring VITE_TURNSTILE_SITE_KEY
and a turnstile.render mock that invokes no callback; advance the clock by 10
seconds, assert signInWithGoogle rejects, and verify
supabaseAuthMock.signInWithIdToken was not called. Restore timers after the
test.
In `@supabase/functions/before-signup/index.ts`:
- Around line 95-97: Update the 405 response returned by the before-signup
handler to include an Allow header set to POST alongside the existing
Content-Type header, while preserving the current error body and status.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4ffffaf6-b175-4446-a664-dcd27a4aa5f9
📒 Files selected for processing (10)
.env.example.github/workflows/deploy-cloudflare.yml.github/workflows/preview-cloudflare.ymlindex.htmlpublic/_headersscripts/cspHeaders.jssrc/security/cspHeaders.test.jssrc/services/authService.jssrc/services/authService.test.jssupabase/functions/before-signup/index.ts
- Add fake-timer test for Turnstile challenge timeout rejection path - Return Allow: POST header on before-signup 405 responses
Contribution workflow
develop: This PR targetsdevelop, notmain. (If the base is wrong, edit the PR on GitHub and change the base branch.)Description
New Google signups were rejected by the
before-signuphook withturnstile_failedbecause the Turnstile server secret was enforced while the client never sent a token in production.Root causes:
VITE_TURNSTILE_SITE_KEYwas missing from Cloudflare deploy/preview CI (Vite stubbedgetTurnstileToken()to alwaysnull), the Turnstile script tag had been removed fromindex.html, and CSP did not allowchallenges.cloudflare.com. Existing accounts still signed in normally (Before User Created does not run for returning users).This PR restores the client path end-to-end, hardens failure UX when the site key is configured, quiets Telegram noise from GET probes on
before-signup, and documents/wires the public site key for CI.Ops required after merge (not in this PR):
VITE_TURNSTILE_SITE_KEY(Cloudflare Turnstile site key).TURNSTILE_SECRET_KEYis set.bayanflow.com,dev.bayanflow.com,localhost(and preview hosts if testing auth on Workers previews).before-signupso alert/405 changes go live.Type of Change
Related Issues
Fixes #
Changes Made
index.html(api.js?render=explicit).https://challenges.cloudflare.comin CSP (script-src,connect-src,frame-src) and asserted it inscripts/cspHeaders.js+ tests.getTurnstileToken()/signInWithGoogle(): when the site key is set, missing script or challenge failure throws before calling Auth; when unset, omit metadata (local/CI fail-open).VITE_TURNSTILE_SITE_KEYintodeploy-cloudflare.ymlandpreview-cloudflare.yml.TURNSTILE_SECRET_KEYin.env.example.before-signup: non-POST returns HTTP 405 without Telegram;turnstile_failedalerts includeemailandip.authServiceand CSP unit tests for Turnstile paths.Algorithm Details (if applicable)
N/A
Testing
pnpm test:run)Test Results
Manual verification (post-deploy)
turnstile_failedTelegram alert.before-signupURL does not send a Telegram alert.Screenshots/GIFs
N/A — auth/security wiring, no UI layout change.
Code Quality
pnpm lint)pnpm format)Performance Impact
Accessibility
N/A — invisible Turnstile widget; no interactive UI surface changes.
Breaking Changes
Checklist
Additional Notes
VITE_TURNSTILE_SITE_KEY, production builds will again omit the token and new signups will fail whileTURNSTILE_SECRET_KEYremains set on Supabase.Reviewer Guidelines:
VITE_TURNSTILE_SITE_KEYis present in repo secrets before relying on production signupSummary by CodeRabbit
New Features
Bug Fixes
Security