Skip to content

fix(auth): Decode form-encoded OAuth2 token responses - #127812

Closed
joshuarli wants to merge 1 commit into
masterfrom
fix/auth-oauth2-form-encoded-token
Closed

joshuarli wants to merge 1 commit into
masterfrom
fix/auth-oauth2-form-encoded-token

Conversation

@joshuarli

Copy link
Copy Markdown
Member

OAuth2Callback.exchange_token passed the raw response body (bytes) to parse_qsl when the token endpoint answers with application/x-www-form-urlencoded. On Python 3 that does not raise, it returns a dict with bytes keys and values, so the later "error" in data / "error_description" in data checks never match and data["access_token"] raises KeyError. The body is now decoded as UTF-8 first, matching sentry.identity.oauth2.OAuth2CallbackView.exchange_token.

JSON responses are unaffected. No test added: the existing tests for this module need the database.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 16, 2026
@getsantry

getsantry Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry Bot added the Stale label Nov 7, 2026
OAuth2Callback.exchange_token passed the response body as bytes to parse_qsl for form-encoded token responses. That returned a dict with bytes keys, so error checks never matched and later lookups of access_token raised KeyError. Decode the body as UTF-8 first, as the identity OAuth2 callback already does.
@joshuarli

Copy link
Copy Markdown
Member Author

Consolidated into #130967 as part of the typing campaign cleanup; code unchanged from the individually validated draft. Tracked in #130956.

@joshuarli joshuarli closed this Nov 12, 2026
joshuarli added a commit that referenced this pull request Nov 26, 2026
Consolidates the previously separate drafts #127797 and #127812 into one
review unit; the code is unchanged from those individually validated drafts.

- social auth copies the request-token and auth extra-argument settings
  before mutating them with request data
- oauth2 decodes form-encoded token response bodies before parsing form
  values

Integrated in #130956.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GitHub Team: python-typing Scope: Backend Automatically applied to PRs that change backend components Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant