Repository navigation
Description
Summary
CIMD clients can bypass the OAuth proxy's scope policy. CIMDClientManager builds the synthetic ProxyDCRClient with scope=cimd_doc.scope or self.default_scope, taking the scope verbatim from the client-hosted metadata document. OAuthProxy never passes its valid_scopes allowlist to the manager, so a CIMD document declaring scope="admin" passes the SDK's client.validate_scope() gate, is recorded in the OAuth transaction, and is forwarded to the upstream IdP — even when the proxy is configured with valid_scopes=["read"]. The equivalent DCR registration/authorization for admin is rejected with invalid_scope.
Reproduction (offline, current main adf90b6)
OAuthProxy(valid_scopes=["read"], required_scopes=["read"], require_authorization_consent=False) with the CIMD fetcher stubbed to return a document declaring scope="admin"; a GET /authorize for that CIMD client yields:
advertised / registerable valid_scopes: ['read']
DCR scope check rejects 'admin': True
CIMD client accepted by get_client: https://client.example.com/oauth-client.json
client.scope granted from document: 'admin'
validate_scope('admin') result: ['admin']
stored transaction scopes: ['admin']
upstream authorize URL: https://idp.example.com/authorize?...&scope=admin&...
RESULT: CIMD client can request and forward a scope outside valid_scopes (DCR clients cannot)
Expected: invalid_scope for the CIMD client as well, and admin must never be recorded or forwarded. The synthetic client's allowed scope set should be the intersection of the document's declared scope and the server's valid_scopes (or required_scopes when valid_scopes is absent), not the document's scope alone.
Suggested fix
Thread the server's allowlist into CIMDClientManager (all construction sites, including OAuthProxy) and intersect the document scope when constructing the client. Keep the existing default_scope fallback when the document omits scope, and refresh the allowlist in update_default_scopes().
The same constraint must also apply to the legacy stored-CIMD-client fallback in OAuthProxy.get_client(): when the CIMD refresh fetch fails, the persisted client carries its verbatim document scope, so it must be sanitized with the same allowlist before being returned.
Tests
A fix with manager-level and HTTP-level regression tests is ready: an out-of-allowlist document scope now fails the scope gate with invalid_scope and forwards no scope upstream, while a document scope inside the allowlist still authorizes and is recorded. I'll open the linked PR with the red/green evidence.
Activity