Impact Duende.AspNetCore.Authentication.OAuth2Introspection didn't keep introspection results apart per authentication scheme
Description
Impact
Duende.AspNetCore.Authentication.OAuth2Introspection didn't keep introspection results apart per authentication scheme. In an application that registers more than one introspection scheme, a token that one scheme's authorization server considers active could also authenticate requests to endpoints protected by another scheme, without that scheme's own introspection endpoint being called.
An attacker who holds a token that one of the schemes accepts, for example as a user of a partner authorization server, or who controls an authorization server that one of the schemes trusts, could use it on endpoints of another scheme. Endpoints that only require an authenticated user accept the request. Endpoints that check claims accept it when the claims returned by the first authorization server satisfy their policy; an authorization server controlled by the attacker can return any claims.
Note: this vulnerability does **not** let an attacker use a token that none of the configured authorization servers accepts.
Are you affected?
You are affected if your application registers two or more introspection schemes in the same process, for example to accept tokens from two authorization servers, and protects different endpoints with different schemes:
builder.Services.AddAuthentication()
.AddOAuth2Introspection("internal", options => { /* ... */ })
.AddOAuth2Introspection("partner", options => { /* ... */ });Separate applications that share a distributed cache (IDistributedCache behind HybridCache) for introspection results are affected in the same way when they don't use a distinct CacheKeyPrefix.
Applications that use a single introspection scheme and don't share a distributed cache with other applications are not affected.
After you upgrade:
- Introspection results cached by earlier versions are no longer used, so each token is introspected once more after the upgrade.
- Separate applications that share a distributed cache and use the same scheme name still need a distinct
CacheKeyPrefixeach.
Workarounds
- Set a distinct
CacheKeyPrefixfor each introspection scheme, and for each application that shares a distributed cache. This prevents one scheme from using results cached by another. - A distinct
CacheKeyPrefixdoesn't protect concurrent requests on different schemes. Until you can upgrade, host schemes that must not accept each other's tokens in separate processes. - Authorization policies that require claims only the intended authorization server issues, such as an audience or scope specific to the API, limit the impact when the authorization servers are not controlled by an attacker.
Credits
Found by Duende Software during an internal security review.