Conversation
Summary of ChangesHello @nickpismenkov, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the OAuth authentication system by enabling dynamic frontend callback URLs. This feature allows client applications to specify where they should be redirected after completing the OAuth flow, providing greater flexibility in integrating with various frontend environments. The changes involve updating the database schema, modifying the OAuth initiation and callback logic, and adding robust testing to ensure proper functionality and security. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Code Review - PR #273: feat: dynamic redirect uri
|
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic redirect URI for OAuth flows by adding an optional frontend_callback parameter. The changes span the API routes, database repository, and include a new migration and tests. The implementation correctly persists the callback URL and adds logic to redirect users after authentication.
My review has identified a few issues:
- A critical security vulnerability (Open Redirect) exists because the
frontend_callbackURL is not validated against a whitelist. This could allow an attacker to steal user tokens. - There is a bug in how the final redirect URL is constructed, which will fail for callback URLs that already contain query parameters.
- The comments in the new test file are slightly misleading about what is being tested.
I have provided specific comments and suggestions to address these points. Overall, this is a valuable feature, but the security and correctness issues should be addressed before merging.
There was a problem hiding this comment.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on January 9
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
|
@claude review |
|
/gemini review |
PR Review - Critical Issues Found
|
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic redirect URI feature for OAuth flows, which is a great enhancement for supporting multiple frontends. The changes are well-structured, including database migration, repository updates, and new tests for the data layer. However, I've found a critical issue in how the redirect URL is constructed, which could break the feature in many cases. I've provided a suggestion to fix this. I also noticed that with the fix, a newly added dependency is no longer necessary and can be removed.
|
@claude review |
Code Review - PR #273: Dynamic OAuth Frontend RedirectsCritical Issues Found
|
|
@claude review |
Security & Logic Review - CRITICAL ISSUES FOUND
|
5e89879 to
d219915
Compare
d219915 to
ecd5c51
Compare
|
@claude review |
Code Review - PR #273: Dynamic redirect URII've reviewed this PR focusing on critical security, logic, and production safety issues. Here are my findings: CRITICAL ISSUES1. Open Redirect Vulnerability - Missing Query Parameter ValidationLocation: crates/api/src/routes/auth.rs, lines ~476-479 The redirect URL validation checks origin, path traversal, and username, but does NOT validate query parameters. An attacker can inject malicious query parameters that could execute XSS if frontend blindly trusts query params, perform CSRF attacks via carefully crafted query strings, or bypass frontend security via parameter pollution. Example Attack: frontend_callback=https://allowed-origin.com/auth?redirect=https://evil.com The validation would pass (origin is allowed, no traversal), but the frontend might redirect to evil.com based on the redirect parameter. Fix: Add query parameter validation or reject URLs with query strings. 2. Token Exposure in URL FragmentsLocation: crates/api/src/routes/auth.rs, lines ~476-484 While URL fragments don't appear in server logs or Referer headers (good!), they ARE stored in browser history (contrary to the comment), ARE accessible via JavaScript to any script on the page, and CAN be leaked via browser extensions, analytics tools, or compromised frontend code. This is particularly dangerous in a multi-tenant OAuth flow where frontends may have varying security postures. Recommendation: Consider using one of these more secure approaches:
Note: If fragment approach is intentional (for mobile/SPA deep-linking), document the security tradeoffs and ensure frontends immediately extract and clear the fragment. 3. Race Condition in OAuth State ValidationLocation: crates/api/src/routes/auth.rs, lines ~177-229 The frontend_callback validation happens in two separate places during OAuth flow: at login initiation and at callback. Between these steps, the CORS configuration could change (e.g., during a rolling deployment). An attacker could start OAuth with a currently-allowed origin, wait for config update that removes that origin, then complete OAuth and get redirected despite origin no longer being allowed. Fix: Consider storing the allowed status in the oauth_states table or accept that callback-time validation is authoritative. 4. Database Migration - Missing Backward Compatibility AnalysisLocation: V0034__add_frontend_callback_to_oauth_states.sql The migration adds a nullable column frontend_callback TEXT to oauth_states. During rolling deployment, old instances won't process frontend_callback redirects correctly. What happens if an old instance handles the callback after a new instance stored the frontend_callback? Recommendation: Document rollout strategy or add a feature flag to ensure all instances are upgraded before frontend_callback is used. MEDIUM PRIORITY ISSUES5. Insufficient URL Validation Edge CasesCurrent validation misses several edge cases: javascript: and data: URIs, IP addresses, homograph attacks, and URL normalization issues. Add scheme validation to only allow HTTP/HTTPS. 6. Missing Rate Limiting on OAuth EndpointsThe github_login and google_login endpoints create database rows without rate limiting. An attacker could spam oauth_states table with junk entries causing database bloat. GOOD PRACTICES OBSERVED
VERDICT: Changes RequestedThis PR has good security awareness but needs fixes for:
|
|
@claude review |
71ab48d to
efc8401
Compare
- Added a new function `validate_frontend_callback` to encapsulate the validation logic for frontend callback URLs, ensuring they meet security requirements. - Updated the GitHub and Google login functions to utilize the new validation function, improving error handling and reducing code duplication. - Enhanced tests to cover various scenarios for frontend callback URLs, including validation against special characters and query parameters.
|
@claude review |
Code Review - PR #273I've reviewed this PR and found one critical security issue that must be addressed before merge.
|
a4d4af9 to
e669fbd
Compare
|
@claude review |
Code Review - Critical Issues Found
|
|
@claude review |
PR Review: Dynamic Redirect URII've analyzed this PR focusing on critical issues. Here are my findings:
|
crates/database/src/migrations/sql/V0034__add_frontend_callback_to_oauth_states.sql
Outdated
Show resolved
Hide resolved
…k_to_oauth_states.sql Co-authored-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
Note
Adds validated
frontend_callbackto OAuth login/callback to redirect users back to allowed frontends with tokens in URL fragment, persisting state in DB.frontend_callbackquery param toGET /v1/auth/githubandGET /v1/auth/google; persist inoauth_statesand use on/v1/auth/callbackto redirect back to frontend withtokenandrefresh_tokenin URL fragment (encoded).validate_frontend_callbackenforces HTTPS (except localhost), blocks userinfo, traversal, queries/fragments, and checks origin viais_origin_allowed(nowpub).V0034__add_frontend_callback_to_oauth_states.sqladdsfrontend_callbackcolumn.OAuthStateRepository: extendcreate/get_and_deleteto handlefrontend_callback; return it from queries.e2e_oauth_frontend_callback.rsfor storing/retrieving callbacks and replay protection.createsignature and callback scenarios.urlencodingfor encoding tokens in callback fragment.Written by Cursor Bugbot for commit 6a0013a. This will update automatically on new commits. Configure here.