Skip to content

fix: repair sanitized redirect_uri test and prettier formatting#2

Merged
terfex merged 3 commits into
fix/exchange-auth-code-sanitize-redirect-urifrom
claude/review-kinde-pr-tests-z9Ssl
May 11, 2026
Merged

fix: repair sanitized redirect_uri test and prettier formatting#2
terfex merged 3 commits into
fix/exchange-auth-code-sanitize-redirect-urifrom
claude/review-kinde-pr-tests-z9Ssl

Conversation

@terfex
Copy link
Copy Markdown
Member

@terfex terfex commented May 11, 2026

$(cat <<'EOF'

Summary

  • Fixed the failing sends a sanitized redirect_uri so /token matches the /authorize value test in lib/utils/exchangeAuthCode.test.ts
  • Fixed prettier formatting violations in lib/sessionManager/types.ts and lib/utils/exchangeAuthCode.test.ts

Root Cause

The new test was missing two things required before exchangeAuthCode reaches the fetch call:

  1. An active MemoryStorage with matching state and codeVerifier session items — without these the function returns early with an "Invalid state" error
  2. A fetchMock response — without it the mock call list is empty, causing the destructure const [, requestInit] = ... to throw TypeError: undefined is not iterable

It also used (global.fetch as jest.Mock) inconsistently with the surrounding tests that use fetchMock, and tried to parse the body as a string when exchangeAuthCode passes a URLSearchParams object directly.

Changes

  • lib/utils/exchangeAuthCode.test.ts: Added MemoryStorage + setActiveStorage setup, fetchMock.mockResponseOnce, and corrected body access pattern to match the rest of the test suite
  • lib/sessionManager/types.ts: Prettier reformatting of the SessionBase class generic constraint

Test plan

  • npm run lint — passes (no prettier or eslint errors)
  • npm test -- --run — 619 passed, 20 skipped, 0 failed

https://claude.ai/code/session_01MfwF59xe6Rs5kyxnQuPRAR
EOF
)


Generated by Claude Code

claude added 2 commits May 11, 2026 15:52
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
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44dd08ca95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/utils/exchangeAuthCode.ts Outdated
code_verifier: codeVerifier,
grant_type: "authorization_code",
redirect_uri: redirectURL,
redirect_uri: sanitizeUrl(redirectURL),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve raw redirect URI when sanitization is disabled

When callers use generateAuthUrl(..., { disableUrlSanitization: true }), the authorize request deliberately sends the raw redirectURL via mapLoginMethodParamsForUrl (for example preserving a trailing slash). This new unconditional sanitizeUrl(redirectURL) changes the value sent to /oauth2/token, so any flow that opted out of sanitization or relies on an exact trailing/double-slash redirect URI will exchange a different redirect_uri than the one used at authorization time and be rejected by the provider. The exchange path needs the same sanitization decision/value that was used to build the authorize URL.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude[agent] please review

@terfex terfex changed the base branch from main to fix/exchange-auth-code-sanitize-redirect-uri May 11, 2026 15:55
Copilot stopped work on behalf of terfex due to an error May 11, 2026 15:58
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
@terfex
Copy link
Copy Markdown
Member Author

terfex commented May 11, 2026

@codex please check

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@terfex terfex merged commit 2682983 into fix/exchange-auth-code-sanitize-redirect-uri May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants