Skip to content

fix(auth): copy social auth settings and decode OAuth form tokens - #130967

Draft
joshuarli wants to merge 1 commit into
masterfrom
josh/typing-bundle/auth
Draft

joshuarli wants to merge 1 commit into
masterfrom
josh/typing-bundle/auth

Conversation

@joshuarli

Copy link
Copy Markdown
Member

Combines two typing-campaign drafts into one review unit; the code is unchanged from the individually validated drafts.

Integrated in #130956.

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.
@joshuarli
joshuarli force-pushed the josh/typing-bundle/auth branch from 6a6edf1 to aabe111 Compare November 26, 2026 00:01
Comment on lines 127 to +128
if req.headers["Content-Type"].startswith("application/x-www-form-urlencoded"):
return dict(parse_qsl(cast(Any, body)))
return dict(parse_qsl(body.decode("utf-8")))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

exchange_token KeyErrors when token response omits Content-Type

Use req.headers.get("Content-Type", "") before startswith; a missing header raises KeyError and aborts SSO. The identity OAuth path already does this.

Evidence
  • exchange_token does req.headers["Content-Type"].startswith(...) on the external token response.
  • safe_urlopen/requests responses do not guarantee a Content-Type header.
  • Missing header raises KeyError before form or JSON parsing.
  • Parallel path in identity/oauth2.py uses req.headers.get("Content-Type", "").lower().

Identified by Warden · sentry-backend-bugs · YME-8BT

Comment on lines 129 to 130
data = orjson.loads(body)
return data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

exchange_token leaves orjson.loads failures uncaught

Wrap orjson.loads(body) in try/except JSONDecodeError and surface a pipeline error; non-JSON IdP bodies currently crash token exchange.

Evidence
  • Non-form branch calls bare orjson.loads(body) on the external response body.
  • IdP error pages or wrong content types can be HTML/plain text, not JSON.
  • No local handler; JSONDecodeError propagates out of dispatch → exchange_token.
  • identity/oauth2.py catches orjson.JSONDecodeError and returns a controlled error payload.

Identified by Warden · sentry-backend-bugs · 2XB-5GN

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant