Repository navigation
Introspection answers only authenticate on the scheme and host that asked for them - #393
Merged
Merged
Conversation
An introspection answer is only valid for the scheme whose own endpoint and client credentials produced it (RFC 7662 section 2.2). Two places let it cross that boundary: - The cache key had no scheme in it. The handler now puts the scheme name, with its length, in front of the CacheKeyGenerator output. The length keeps names that contain ':' from spelling another scheme's key. This also covers custom key generators. - The static in-flight map was keyed by token only, so a request on one scheme, or in another host in the same process, could join a call made for someone else. It is now keyed by the options instance and token, which is one entry per scheme per host, like the client assertion state the handler already keeps on the options. Cached entries written by earlier versions are not read any more; each token is introspected once more after the upgrade.
pgermishuys
approved these changes
Nov 16, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A shared-cache key collision with legacy hosts can cause the new handler to accept another authority’s active response, requiring a collision-safe key format, custom-generator migration guidance, and a regression test.
1 open issue
What changed in this PR
This PR isolates introspection answers between authentication schemes and prevents concurrent requests in separate hosts from sharing an authority’s response.
Changes:
- Adds a length-prefixed scheme name to cache keys, including custom-generated keys.
- Keys shared in-flight calls by options instance and token.
- Adds scheme and host isolation tests and updates existing cache-key assertions.
| File | Description |
|---|---|
introspection/test/AspNetCore.Authentication.OAuth2Introspection.Tests/IntrospectionAnswerIsolation.cs |
Adds sequential, concurrent, cross-host, and ambiguous-key isolation tests. |
introspection/test/AspNetCore.Authentication.OAuth2Introspection.Tests/Introspection.cs |
Updates cache assertions for scheme-qualified keys. |
introspection/src/AspNetCore.Authentication.OAuth2Introspection/OAuth2IntrospectionHandler.cs |
Scopes cache keys by scheme and in-flight calls by options instance. |
introspection/src/AspNetCore.Authentication.OAuth2Introspection/Infrastructure/CacheExtensions.cs |
Accepts precomputed keys for cache reads and writes. |
Review effort: Balanced
| } | ||
|
|
||
| var claims = await _cache.GetClaimsAsync(Options, token).ConfigureAwait(false); | ||
| var cacheKey = $"{Scheme.Name.Length}:{Scheme.Name}:{Options.CacheKeyGenerator(Options, token)}"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

An API can register more than one introspection scheme, each with its own authorization server and client credentials. Each scheme now only trusts answers from its own introspection endpoint. Before this change, a token that one scheme accepted could also authenticate on another scheme, without that scheme ever asking its own authorization server.
Explanation
There were two ways for an answer to cross over:
{CacheKeyPrefix}{sha256(token)}. Nothing in it says which scheme stored the entry, so with the default empty prefix, two schemes read and write the same entry.The handler now puts the scheme name in front of whatever
CacheKeyGeneratorreturns, and the shared calls are keyed by the scheme's options instance and the token.Before and after
A token is active at the partner authorization server and inactive at the internal one. Before: after a request to the partner endpoint, the same token got a 200 on the internal endpoint and the internal authorization server was never called. After: the internal scheme asks its own server and returns 401. This holds for requests in a row and at the same time, and also for two hosts in one process that use the same scheme name.
Decisions
CacheKeyPrefix, so custom key generators and schemes with equal prefixes are covered too.6:Bearer:...), so a scheme nameda:bcan't produce the same key as schemeawith prefixb:.Upgrade notes
CacheKeyPrefixeach, as before.Where to look
OAuth2IntrospectionHandler.cs: the cache key and the in-flight key.Infrastructure/CacheExtensions.cs: now takes the key instead of building it.