Skip to content

Ignore client-supplied scope on RFC 8628 device token requests - #1002

Merged
JonathanHuot merged 1 commit into
masterfrom
vibe/device-grant-scope-integrity-2e5d59
Oct 30, 2026
Merged

JonathanHuot merged 1 commit into
masterfrom
vibe/device-grant-scope-integrity-2e5d59

Conversation

@JonathanHuot

Copy link
Copy Markdown
Member

Summary

  • The token endpoint (TokenEndpoint.create_token_response) pre-fills request.scopes from the untrusted scope parameter for every grant. For the RFC 8628 device grant, this defeated the issue Add validate_device_authorization_code() to RequestValidator to give DeviceCodeGrant symmetry with Authorization Code Grant #944 consent-integrity guard: whenever validate_device_code did not populate request.scopes from the stored authorization, the token was issued for the attacker-supplied scopes (validated only against the client's registration), instead of failing loudly.
  • DeviceCodeGrant.validate_device_code now neutralizes the parameter path for an authorized device code: it clears request.scopes and request.scope before checking the stored authorization. If the validator did not populate request.scopes, the grant still fails with server_error ("validate_device_code must set request.scopes for an authorized device_code.") rather than minting a token for untrusted scopes.
  • Clarified DeviceClient.prepare_request_body docs: RFC 8628 Section 3.4 token requests carry no scope parameter and oauthlib-based servers ignore it.

Verification

  • python -m pytest tests/oauth2/rfc8628 -q — 40 passed (39 existing + 1 new regression test)
  • python -m pytest tests/oauth2 -q — only the 7 pre-existing failures in rfc6749/test_parameters.py, identical on clean master

Closes #944

The token endpoint pre-fills request.scopes from the untrusted scope
parameter before the grant runs, which allowed a device-flow client to
obtain a token for any scope within its own registration whenever
validate_device_code did not populate request.scopes, bypassing the
issue #944 consent-integrity guard. Clear scopes on the authorized
path so the grant fails loudly unless the stored authorization
populates them.

Co-authored-by: JonathanHuot <[email protected]>
@JonathanHuot
JonathanHuot marked this pull request as ready for review October 30, 2026 22:50
@JonathanHuot JonathanHuot added Bug OAuth2-Provider This impact the provider part of OAuth2 labels Oct 30, 2026
@JonathanHuot
JonathanHuot merged commit 3fde215 into master Oct 30, 2026
32 checks passed
@JonathanHuot JonathanHuot mentioned this pull request Oct 31, 2026
@JonathanHuot JonathanHuot added this to the 5.0.0 milestone Oct 31, 2026
@JonathanHuot JonathanHuot added the Breaking Breaking change, to go in the next major release. label Oct 31, 2026 — with MistralAI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking Breaking change, to go in the next major release. Bug OAuth2-Provider This impact the provider part of OAuth2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add validate_device_authorization_code() to RequestValidator to give DeviceCodeGrant symmetry with Authorization Code Grant

2 participants