NewApp Monitoring is liveSign up free
AgentbeamBeta
Open-source package vulnerability · PyPI

CVE-2026-49272: OAuthLib: Bearer token can be retrieved as long as client knows a valid client ID for device workflow

highCVSS 3.1 8.5GHSA-3jp2-3mrg-2vxc

OAuthLib 3.3.0 up to 4.0.0 does not validate `device_code` at the token endpoint in `DeviceCodeGrant.validate_token_request`. A caller who knows a client ID enabled for the device flow can send any `device_code` and receive a bearer token. Fixed in oauthlib 4.0.0.

Published Oct 27, 2026 · Updated Nov 5, 2026 · Analysis Nov 1, 2026

What an attacker can do

RFC 8628 section 3.4 requires the token endpoint to take device_code as a parameter and check it. DeviceCodeGrant.validate_token_request does none of that. It does not require the parameter and does not verify its value. The authorization code grant, by contrast, validates its code.

The reporter's setup is a public client. Their authenticate_client returns true for clients of type public, which is needed because of a separate public-client handling issue in the same method. A request with grant_type set to urn:ietf:params:oauth:grant-type:device_code, a valid client_id and any device_code returns a bearer token.

The attacker needs a valid client ID for a client enabled for the device flow, and nothing else; no real user ever approves a device. Client IDs of public clients are not secret. The advisory says anyone using the device workflow in oauthlib who did not know device_code is unchecked is affected. The token is issued for that client, so the attacker gets whatever access the client's tokens carry. CVSS 3.1 gives 8.5 with high integrity impact and changed scope.

Who is affected

Affected: oauthlib from 3.3.0 up to but not including 4.0.0. Check:

pip show oauthlib

You are exposed if your server uses oauthlib's RFC 8628 device flow (DeviceCodeGrant) at the token endpoint. Servers without the device grant are not touched by this bug.

oauthlib

Ecosystem
PyPI
Affected
>= 3.3.0, < 4.0.1
Fixed in
4.0.1
Check
pip show oauthlib

How to fix it

Upgrade to oauthlib 4.0.0:

pip install --upgrade oauthlib==4.0.0

The reporter proposed a validate_device_code method on RequestValidator, called from DeviceCodeGrant.validate_token_request, similar to validate_code. Check the 4.0.0 release notes for how your validator must implement the check. The advisory names no workaround. As a stopgap, enforce the device_code check yourself before the token endpoint calls oauthlib, or turn off the device grant.

How to tell if you were hit

Review token endpoint logs for requests with grant_type=urn:ietf:params:oauth:grant-type:device_code whose device_code value was never issued by your authorization endpoint. Compare issued device codes with codes presented. Look for bearer tokens issued to device-flow clients with no matching user approval record.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Summary

A call to the token endpoint with a grant type of "urn:ietf:params:oauth:grant-type:device_code" and a bogus device_code is able to get a bearer token as long as they know a valid client ID enabled for the device workflow.

Details

Section 3.4 of the RFC 8628 spec says that the token endpoint should take in device_code as a required parameter.DeviceCodeGrant.validate_token_request does not perform any validation of device_code. DeviceCodeGrant.validate_token_request should be validating that device_code was passed in as a parameter and that it is valid, similar to how AuthorizationCodeGrant.validate_token_request does the checks here and here.

I would like to propose a new method be added to RequestValidator called validate_device_code that is similar to the validate_code method and is called inside of DeviceCodeGrant.validate_token_request.

PoC

Create an implementation of RequestValidation.authenticate_client that returns True if the client's client_type is "public". You would find yourself in this scenario because there's another issue with DeviceCodeGrant.validate_token_request where it doesn't properly handle public clients (see https://github.com/oauthlib/oauthlib/issues/919).

Create a client that has a client_type of "public" and set it's grant_type to "urn:ietf:params:oauth:grant-type:device_code".

With this implementation of RequestValidation.authenticate_client done, use that validator for your token endpoint. Call the token endpoint with a body of

{
  "client_id": <ID of the public client you made>,
  "grant_type": "urn:ietf:params:oauth:grant-type:device_code",
  "device_code": <anything you want since it's not validated>
}

You now have a bearer token for the client without a valid device_code.

Impact

Anyone using the RFC 8628 device workflow in oauthlib that doesn't realize the device_code parameter is not being validated.

Credited to hekhuisk, Rania193.

Questions

Do I need a secret to exploit this?

No client secret is needed in the reporter's setup. A valid client ID for a client enabled for the device flow is enough, and the device_code can be any value.

Does it affect the authorization code flow?

The advisory is about DeviceCodeGrant only. It notes AuthorizationCodeGrant.validate_token_request does check its code.

Which oauthlib version fixes CVE-2026-49272?

4.0.0. The affected range runs from 3.3.0 up to but not including 4.0.0.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More PyPI vulnerabilities

All PyPI entries