Uh oh!
There was an error while loading. Please reload this page.
fix(calendar): restore Google Calendar OAuth connect flow (#61) - #407
Conversation
Warning Review limit reached
Next review available in:29 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. 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: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
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 |
Deploying with |
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs | frontend-staging | 62a97c1 | Commit Preview URL Branch Preview URL | Jul 29 2026, 10:28 AM |
Rebase of PR #407 onto current main (ea2ab0b, ~127 commits ahead of the original branch point). The true diff applied cleanly with git apply -3; no textual conflicts. Re-verified every reused primitive against main's evolved auth/encryption structure (0024 identity split). The dedicated calendar consent flow — GET /api/calendar/auth-url and /api/calendar/callback — was dropped in the SQLite→Supabase migration, but config.GOOGLE_SCOPES / GOOGLE_REDIRECT_URI and the frontend "Connect Google" button (Calendar.tsx → calendarAuthUrl) still point at it. With the routes gone, clicking "Connect Google" 404'd, so users could never (re)grant calendar access and /sync, /export, /import all failed with 401 "Not connected to Google Calendar." This is the root cause of #61. - Restore both routes, reusing the sign-in flow's OAuth primitives (PKCE + HMAC-signed state cookie) from routes/auth.py as the single source of truth for CSRF handling — no duplication of the security-critical bits. On current main these helpers still live in routes/auth.py (session minting moved to services/session_tokens.py, but the OAuth state/PKCE helpers did not). - Auth scoping (the #61 comment, sibling of the #123 export IDOR): the user_id is sealed into the signed state cookie after require_self, and the callback reads it from that cookie — never from a request parameter — so the minted tokens can only ever bind to the session that initiated connect. - Request access_type=offline + prompt=consent so a refresh_token is always returned; otherwise sync breaks once the access token expires. - Token storage follows main's encryption boundaries: encrypt(access_token), encrypt_if_present(refresh_token), upsert on_conflict=user_id — byte-for- byte the same shape as the sign-in callback's oauth_tokens write. - Fix a latent refresh bug: _get_refreshed_credentials wrote expires_at="" when a refresh yielded no expiry, but expires_at is TIMESTAMPTZ (migration 0024) and "" is not a valid timestamptz (auth.py fixed the same hazard). - The calendar flow uses GOOGLE_REDIRECT_URI (/api/calendar/callback), kept distinct from the sign-in flow's GOOGLE_AUTH_REDIRECT_URI, via _calendar_client_config re-pointing the shared client config. Tests: new test_calendar_oauth_connect.py covers the happy path, the CSRF boundary (nonce mismatch / missing cookie / user-denied), token binding to the cookie user, and the expires_at=None refresh fix. Full suite green on main's tip: 1231 passed, 27 skipped. ruff check clean (zero findings, same as the origin/main baseline). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
c6eeed2 to
0dd341dCompare…rite needs schema backing (review finding) The expires_at=None 'fix' traded an invalid-timestamptz cast for a not-null violation (0001 baseline constraint; 0024 only retyped the column) — a refresh PATCH would 500 AND lose the fresh access_token. Readers already treat NULL as 'no known expiry'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
Fixes #61 — Google Calendar sync doesn't work for the calendar feature.
Root cause: The dedicated calendar OAuth connect flow —
GET /api/calendar/auth-urlandGET /api/calendar/callback— was dropped during the SQLite→Supabase migration (last present inff814e0), butconfig.GOOGLE_SCOPES/config.GOOGLE_REDIRECT_URIand the frontend "Connect Google" button (Calendar.tsx→calendarAuthUrl→/api/calendar/auth-url) still target it. With the routes gone, clicking "Connect Google" 404'd, so a user could never (re)grant calendar access and/sync,/export,/importall failed with401 "Not connected to Google Calendar."This also addresses the #61 comment asking to fix the calendar feature's auth scoping holistically (sibling of the #123 export IDOR, which is already fixed on
main).What changed
backend/routes/calendar.py, reusing the sign-in flow's OAuth primitives (PKCE + HMAC-signed state cookie) fromroutes/auth.pyas the single source of truth for CSRF — no duplication of the security-critical bits.user_idis sealed into the HMAC-signed state cookie afterrequire_self, and the callback reads it from that cookie — never from a request parameter. So the minted tokens can only ever bind to the session that initiated the connect, and a forged/mismatchedstatecan never drive a token write.access_type=offline+prompt=consentso a refresh_token is always returned — otherwise sync silently breaks once the access token expires._get_refreshed_credentialswroteexpires_at=""when a refresh yielded no expiry, butexpires_atisTIMESTAMPTZ(migration 0024) and""is not a valid timestamptz (auth.pyfixed the identical hazard). Now writesNone.No frontend change needed — the callback redirects to
/calendar?connected=true, whichCalendar.tsxalready handles.Testing
New
backend/tests/test_calendar_oauth_connect.py:auth-urlredirects to Google, sets the signed state cookie, requests offline + consent; 400 when Google unconfigured.callbackhappy path stores tokens bound to the cookie's user_id,on_conflict=user_id,expires_at=None(not"").?error=) are all rejected with no token write.expires_at=Nonewhencreds.expiryisNone.The 1 failure (
test_flashcard_import_service::TestRateLimit,assert 61 <= 60) and 1 error (test_ocr_pipeline::test_save_to_db, event-loop teardown ordering) are pre-existing flakes unrelated to this change — this PR touches onlycalendar.py+ the new test file, and neither suspect imports them (test_ocr_pipelineeven passes in isolation). All calendar + auth tests pass (117 passed).ruff checkclean.🤖 Generated with Claude Code