Fix/exchange auth code sanitize redirect uri#230
Conversation
Add test to ensure sanitized redirect_uri matches expected value.
The new test was missing storage setup (state + codeVerifier) and a fetchMock response, causing exchangeAuthCode to bail out early before reaching fetch. Also fixes prettier formatting in types.ts and the test file. https://claude.ai/code/session_01MfwF59xe6Rs5kyxnQuPRAR
This file was never tracked in the project and is generated locally by npm install. https://claude.ai/code/session_01MfwF59xe6Rs5kyxnQuPRAR
When callers pass disableUrlSanitization: true to generateAuthUrl the authorize request sends the raw redirectURL. The token exchange must use the same value; unconditionally calling sanitizeUrl() would produce a mismatched redirect_uri and cause the provider to reject the exchange. Adds the disableUrlSanitization option (default false) to ExchangeAuthCodeParams and mirrors the same conditional used in mapLoginMethodParamsForUrl. Also adds a test covering the raw-URI path. https://claude.ai/code/session_01MfwF59xe6Rs5kyxnQuPRAR
fix: repair sanitized redirect_uri test and prettier formatting
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe PR adds conditional URL sanitization to ChangesToken Exchange Redirect URI Sanitization
Unrelated Changes
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
Closes #228
Summary
redirect_uriis sanitized when it's sent to/oauth2/authorize(via
mapLoginMethodParamsForUrl→sanitizeUrl) but not when it's sentto
/oauth2/token(inexchangeAuthCode). BecausesanitizeUrlstripstrailing slashes, any consumer whose configured
redirectURLends in/hits
invalid_grant: "redirect_uri … does not match the one from the authorize request"on token exchange. This applies the samenormalization on both sides so the two requests always agree.
Changes
lib/utils/exchangeAuthCode.ts: wrap the outgoingredirect_uriinsanitizeUrl(...)— matches the existing behavior ofmapLoginMethodParamsForUrl.ts.lib/utils/exchangeAuthCode.test.ts: cover the trailing-slash case.Notes
redirectURLis alreadytrailing-slash-free (which is what authorize was effectively seeing
before this fix anyway).
disableUrlSanitizationflag toexchangeAuthCodeto mirrormapLoginMethodParamsForUrl— butasymmetric defaults are the bug; symmetric defaults are the fix. Happy
to add the opt-out flag if maintainers want it for parity with the
authorize side.
Test plan
npm run lintnpm testChecklist
🛟 If you need help, consider asking for advice over in the Kinde community.