Support allowlist mode and fixed redirect mode simultaneously#19
Conversation
WalkthroughA new FixedRedirectURI option is added and threaded through configuration, environment loading, and OAuth handlers. Redirect decision logic now accepts either a client redirect allowlist (RedirectURIs) or a fixed proxy redirect URI (FixedRedirectURI) across authorize, callback, token, and registration flows. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as OAuth Client
participant Proxy as Proxy Server
participant Provider as OAuth Provider
rect rgb(220, 235, 255)
note over Client,Proxy: Allowlist Mode (RedirectURIs)
Client->>Proxy: GET /authorize?redirect_uri=client://cb
Proxy->>Proxy: Validate redirect_uri against RedirectURIs allowlist
Proxy->>Provider: Redirect to Provider with client's redirect_uri
Provider->>Client: Callback to client's redirect_uri
end
rect rgb(220, 255, 220)
note over Client,Proxy: Fixed Redirect Mode (FixedRedirectURI)
Client->>Proxy: GET /authorize?redirect_uri=client://cb
Proxy->>Proxy: Store client's redirect_uri, sign state
Proxy->>Provider: Redirect to Provider with FixedRedirectURI
Provider->>Proxy: Callback to FixedRedirectURI
Proxy->>Proxy: Validate state, resolve stored client redirect_uri
Proxy->>Client: Proxy callback to stored client redirect_uri
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (1)**/*.go📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (3)📓 Common learnings📚 Learning: 2025-12-13T17:03:53.298ZApplied to files:
📚 Learning: 2025-12-13T17:03:53.298ZApplied to files:
🔇 Additional comments (13)
✏️ Tip: You can disable this entire section by setting 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 |
f05c9d8 to
4965adf
Compare
eefc99c to
1fc82f0
Compare
|
@WhammyLeaf could you help resolve the conflict? |
Of course 😄 |
1fc82f0 to
4a33e7f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@handlers.go`:
- Around line 549-553: Inside the "authorization_code" switch branch you have an
unreachable check if grantType != "authorization_code" that calls h.logger.Error
and http.Error; remove that entire if block (the check and its body) so there is
no dead code referencing grantType, h.logger.Error or http.Error in this branch
and ensure any needed error handling remains only in the outer switch/default
branch.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
config.gohandlers.gometadata.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go
📄 CodeRabbit inference engine (CLAUDE.md)
Never log raw OAuth tokens; only log SHA-256 hash of token formatted as fmt.Sprintf("%x", sha256.Sum256([]byte(token)))[:16]
Files:
metadata.gohandlers.goconfig.go
🧠 Learnings (2)
📚 Learning: 2025-12-13T17:03:53.298Z
Learnt from: CR
Repo: tuannvm/oauth-mcp-proxy PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:03:53.298Z
Learning: Applies to **/*.go : Never log raw OAuth tokens; only log SHA-256 hash of token formatted as fmt.Sprintf("%x", sha256.Sum256([]byte(token)))[:16]
Applied to files:
metadata.go
📚 Learning: 2025-12-13T17:03:53.298Z
Learnt from: CR
Repo: tuannvm/oauth-mcp-proxy PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:03:53.298Z
Learning: Redirect URI validation must use explicit allowlist - all URIs must be in whitelist before authorization
Applied to files:
handlers.go
🔇 Additional comments (11)
metadata.go (1)
197-206: LGTM! Redirect URI fallback logic is well-structured.The cascading fallback from client-provided URIs →
FixedRedirectURI→ singleRedirectURIsis clear and follows the PR's design intent. The trim operations ensure whitespace doesn't cause issues.config.go (4)
14-17: LGTM! Config struct updated correctly.The new
FixedRedirectURIfield is well-documented and follows the existing field naming convention.
93-95: LGTM! Validation logic correctly requires at least one redirect URI source.The OR condition ensures proxy mode has a valid redirect URI configuration from either source.
201-206: LGTM! Builder method follows established pattern.The new
WithFixedRedirectURImethod is consistent with other builder methods in style and functionality.
329-329: LGTM! Environment variable integration is correct.The
OAUTH_FIXED_REDIRECT_URIenvironment variable follows the existing naming convention.handlers.go (6)
43-44: LGTM! OAuth2Config struct updated correctly.The
FixedRedirectURIfield addition with documentation aligns with the config structure changes.
188-205: LGTM! Config mapping includes the new field.The
FixedRedirectURIfield is correctly propagated from the source config.
304-392: Well-designed redirect URI strategy with comprehensive security controls.The cascading approach (allowlist → fixed redirect → reject) is correctly implemented:
- Allowlist mode validates against configured URIs
- Fixed redirect mode restricts to localhost-only, preventing open redirect attacks
- HMAC-signed state protects against tampering
- Scheme validation and HTTPS enforcement add defense in depth
454-487: LGTM! Callback handling correctly triggers proxy mode based on FixedRedirectURI.The defense-in-depth re-validation of localhost URIs even after state verification is a good security practice.
556-560: LGTM! Token exchange redirect logic aligns with authorization flow.The fallback to
FixedRedirectURIwhen the client URI isn't in the allowlist maintains consistency with theHandleAuthorizebehavior.
612-634: LGTM! Token response construction is correct.Tokens are properly included in the response for the client but are not logged. This complies with the coding guideline to avoid logging raw OAuth tokens.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
Signed-off-by: Christian Troelsen <christian.troelsen@tryg.dk> format fix again
86229d2 to
94d5f7a
Compare
@tuannvm Done |
Summary
Right now one of two redirect URI modes is supported:
This PR redesigns the interface of the library so that both modes can be supported at the same time.
It does so by introducing a new
FixedRedirectURIvariable, which defines a single redirect URI for fixed redirect mode. Correspondingly, the existingRedirectURIsvariable now only defines the valid redirect URIs for allow list mode.If
RedirectURIsandFixedRedirectURIare both set, thenRedirectURIstakes precedence. If the client-provided redirect URI is not inRedirectURIsthen fixed redirect mode will be tried next.Changes
handlers.go, specifically in theHandleAuthorize,HandleCallbackandHandleTokenmethods.config.gohandleRegisterfunction inmetadata.gois also updated to properly handle the new fixed redirect modeTesting
Related Issues
#20
Summary by CodeRabbit
New Features
Bug Fixes / Security
✏️ Tip: You can customize this high-level summary in your review settings.