CVE-2026-92857 and CVE-2026-96447: From a Registration Token to Realm Admin in Keycloak
How two stock protocol mappers and a username fallback turn a Keycloak Initial Access Token into realm-admin API access, and how JoFlow, an object-flow tracer built on the Endpoint-SBOM paper, verified my harness's account of it.
Disclaimer. This is an authorized write-up of bugs that are already fixed. Every request below went to Keycloak containers on my laptop, started from the stock images, against throwaway accounts on a disposable instance. Run a patched release.
Table of Contents
- Introduction
- How the Pieces Fit
- The Lab
- The Chain
- Why Keycloak Resolves the Token to Bob
- Verifying the Harness with JoFlow
- The Fixes in 26.8.2
- Closing Notes
- References
Introduction
TL;DR On Keycloak 26.7.2, an attacker with an Initial Access Token can register a client whose protocol mappers copy their own profile values into the access token’s
subandpreferred_usernameclaims. The attacker setssubto an invalid user ID andpreferred_usernameto a target administrator’s username, then obtains a token through the JWT Authorization Grant. That token has no stored session, so Keycloak looks up its user from the claims. The ID lookup fails; the username lookup finds the administrator, and Keycloak loads that user’s administrative roles. The attacker authenticates as themselves, but Keycloak authorizes the request as the target administrator. I used JoFlow to verify this path in the running server. Keycloak 26.8.2 fixes the mapper-registration and username-fallback bugs as CVE-2026-92857 and CVE-2026-96447.
This is an earlier finding from the harness behind the race in my previous post. I reported it to Keycloak back in August, and the two halves later shipped as separate CVEs in 26.8.2.
A note on credit. Keycloak confirmed that my report covered both CVEs and has asked for the published acknowledgements to be updated to include me. That update hadn’t landed at the time of writing.
The bugs are bland: a registration check that let a standard token rule write identity claims such as sub, and a user lookup that trusted a username. The part I want to spend time on is the verification. My harness explained why Keycloak resolved the token to the administrator, and I wanted to see the objects move through Keycloak before I believed it.
The attacker needs three things: a registration token good for one client (Keycloak calls it an Initial Access Token), their own Keycloak account linked to an external identity provider, and the administrator’s username. The PoC below takes the username as known. In my report, the attacker learned it from Keycloak’s account-linking form, starting from the administrator’s email address:
- At the identity provider, the attacker sets that email address on a second account that has never signed in to the target realm (Acme, in the lab below).
- They sign in to Acme with that account. Keycloak sees a new external account whose email matches an existing user and offers to link the two.
- Keycloak would normally confirm the link by email. With no email server configured, it asks for the existing user’s password instead, and fills in that user’s username on the form.
The attacker never needs the password, because the username is already on the screen. Keycloak’s source describes the pre-filled username as deliberate, and 26.8.2 doesn’t change it.
Keycloak’s issue tracker labels CVE-2026-92857 high severity and CVE-2026-96447 medium. Red Hat scores them 8.1 and 4.2 under CVSS 3.1.
How the Pieces Fit
Keycloak gives each app an access token, a signed JSON Web Token (JWT) whose fields are called claims. Figure 1 shows the claims this bug turns on, and how Keycloak finds the user when a token comes back to its own APIs, such as the Account API or the Admin API.
A token from a normal login names its stored session in sid. A token issued on a transient session, one that Keycloak creates for the request and never stores, has no sid.
Figure 1. With sid, the user comes from the stored session. Without it, on a transient session, the user comes from the claims.
Keycloak calls a token without sid stateless. Three Keycloak features let an attacker get a stateless token with claims they chose:
- Dynamic client registration. Anyone holding an Initial Access Token, which an administrator creates with an expiry and a use count, can register a new client (an app) at the realm’s registration endpoint.
- Protocol mappers. Per-client rules that copy data into token claims. The stock
oidc-usermodel-attribute-mappercopies a user attribute, such asfirstName, into whichever claim the mapper names. - JWT Authorization Grant. A client trades a JWT signed by a trusted external identity provider, called an assertion, for a Keycloak access token, following RFC 7523. The grant runs on a transient session, so its tokens carry no
sid. The feature is on by default in 26.7.2. A client opts in with the attributeoauth2.jwt.authorization.grant.enabledand names the trusted provider inoauth2.jwt.authorization.grant.idp.
For more detail, see OpenID Connect Core for sub and the other ID token claims, and Keycloak’s guides to client registration and protocol mappers.
The Lab
The PoC is a Docker Compose stack: the stock quay.io/keycloak/keycloak:26.7.2 image, PostgreSQL 17, and two realms imported at startup into the same Keycloak process.
- Lab IdP. The realm
lab-idpstands in for an external OpenID Connect provider and holdsalice@corp.exampleandbob@corp.example. - Acme. The target realm trusts the Lab IdP as the provider
lab-idp-oidc, with JWT Authorization Grant enabled. Its useraliceis ordinary, andbobholdsrealm-adminon therealm-managementclient. Each is linked to the matching Lab IdP account.
Acme keeps Keycloak’s default client registration policies. During setup, Bob uses his own admin token to create the Initial Access Token with a count of 1 and a 300-second expiry. That models an administrator handing a registration token to a developer.
The PoC runs every step with curl, so it uses two lab client secrets that an attacker wouldn’t normally hold. Alice signs in to the Lab IdP by password through its lab-idp-broker client and uses the ID token as her assertion. Her first, ordinary Acme token comes from the grant client lab-idp-jag-client.
Acme accepts that ID token because its provider configuration sets allowClientIdAsAudience, which is off by default and lets an assertion addressed to lab-idp-broker pass the audience check. In a real deployment, the attacker needs their own way to get an assertion from the trusted provider that Acme accepts.
The Chain
Alice, the attacker, works with her own credentials and the Initial Access Token. Figure 2 shows her five steps in order.
Figure 2. The chain on Keycloak 26.7.2, from a run of the PoC without JoFlow.
- She signs in to the Lab IdP for a signed assertion and trades it through Acme’s existing grant client for an ordinary Acme token.
- With that token she sets her own
firstNametonot-a-real-user-idandlastNametobob. - With the Initial Access Token she registers a confidential client that enables the grant for
lab-idp-oidc, asks for lightweight access tokens, and carries the two mappers in Figure 3. - She signs in to the Lab IdP again and trades the new assertion through her new client. The token that comes back is the forged one.
- She sends the forged token to the Admin API and the Account API, and both treat it as Bob’s.
Figure 3 shows the two mappers from the PoC’s registration request.
Figure 3. Alice’s profile values, the two mappers with the settings that matter, and the claims they write.
The default policy for authenticated registration allows oidc-usermodel-attribute-mapper and doesn’t check which claim it writes. Keycloak ignores mapper writes only to a fixed list of claims, such as iss, exp and jti, and sub and preferred_username aren’t on it.
Why Keycloak Resolves the Token to Bob
The token’s ID records that it was issued on a transient session. When the Admin API’s bearer check finds no sid on such a token, it builds a transient session for it and asks TokenManager.lookupUserFromStatelessToken for the user. On 26.7.2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public static UserModel lookupUserFromStatelessToken(KeycloakSession session, RealmModel realm, AccessToken token) {
// Try to lookup user based on "sub" claim. It should work for most cases with some rare exceptions (EG. OIDC "pairwise" subjects)
UserModel user = token.getSubject() == null ? null : session.users().getUserById(realm, token.getSubject());
if (user != null) {
return user;
}
// Fallback to lookup user based on username (preferred_username claim)
if (token.getPreferredUsername() != null) {
return session.users().getUserByUsername(realm, token.getPreferredUsername());
}
return null;
}
No user has the ID not-a-real-user-id, so the lookup by sub returns null and the username lookup returns Bob. Nothing in the fallback checks that the token’s sub belongs to the user it found.
The fallback exists for pairwise subjects, an OpenID Connect option that gives a client a hashed sub in place of the real user ID, so unrelated apps can’t match up the same user. A hashed sub isn’t a user ID, so getUserById can’t find it, and the lookup falls back to preferred_username.
The roles come from Bob too. Admin permission checks call AuthenticationManager.resolveLightweightAccessTokenRoles, which fills in role claims when a token is lightweight, or has no session and no role claims. Role resolution looks up the user from the token again and gets Bob through the same username fallback. It then writes Bob’s real ID into the token’s subject and copies in his realm and client roles, as far as the token’s client is allowed to see them.
All of Bob’s roles are in scope because the registered client came back with fullScopeAllowed set to true. On 26.7.2, Keycloak’s default “Full Scope Disabled” registration policy is installed only for anonymous registration. In a negative-control run for my report, disabling full scope on the client kept the forged identity in the token, but the Account API returned 401 and the Admin API 403.
Verifying the Harness with JoFlow
Where JoFlow Comes From
JoFlow is built on A Vision for Endpoint-SBOM: Showing Which Dependencies Introduce Runtime APIs by Vishal Maurya and Justin Mills, a preprint published on Zenodo on August 13, 2026. The paper asks which dependency introduced a given HTTP endpoint in a Spring Boot application. Its example is a starter dependency that adds GET /internal/debug without touching the application’s source.
The paper’s prototype reads Spring MVC’s route table at startup. For each handler class it walks from the class to its ProtectionDomain, its CodeSource, the JAR, and the JAR’s META-INF/maven/**/pom.properties to name the Maven artifact. It labels each route first-party, third-party, framework, Actuator, or unknown and compares the set with an approved baseline.
Each change earns points, such as 2 for a new route and 3 for a third-party owner, and the total sets a low, medium, high, or critical rating that a CI job can fail the build on.
What I Kept and What I Added
JoFlow keeps the provenance walk, the refusal to guess a Maven coordinate from a JAR file name, the origin labels (minus Actuator), the baseline comparison, and the points-based rating. Like the paper’s prototype, it writes a JSON manifest for CI and a Markdown report for a person to read.
The question changes from routes to objects: which artifacts’ code an object passes through, and where it gets serialized. To answer that I added:
- A Java agent. Byte Buddy instruments the included classes and records constructors, method arguments, receivers, and return values.
- Object identities. A weak registry gives each observed object a stable ID such as
o2643for the run, without keeping it alive. - Serializer hooks and value snapshots. Calls into Jackson, Gson, Kryo and SnakeYAML that return a value, such as Jackson’s
readValueandwriteValueAsBytes, get a reflective snapshot of the object, with secret-looking field names redacted. - A control port.
/markwrites a labeled marker into the event log,/objectssnapshots live observed objects by class, and/finalizewrites the manifest. - More provenance states. The paper lists shaded JARs, generated proxies, and runtime bytecode generation as open problems and says the system should report them as
UNKNOWNorAMBIGUOUS. JoFlow reportsAMBIGUOUSfor shaded JARs with severalpom.propertiesfiles andSYNTHETICfor proxies, lambdas, hidden classes, and Byte Buddy output. It addsMANIFESTfor JARs that only carryMANIFEST.MFattributes. - Heap dumps and completeness. An optional HPROF heap dump at the end of a run, and a
completeflag that turns false when sampling is on or the event cap is reached.
Nothing in it is Spring-specific, which is why it runs inside Keycloak on Quarkus. JoFlow isn’t public yet.
How I Used It
In August my harness ran JoFlow next to its reproduction to verify its explanation. The trace showed not-a-real-user-id arriving as Alice’s firstName and the target administrator’s identity reaching the Admin API, but it left two questions open. It didn’t show which lookup found the target, because that run didn’t watch the user cache. And it showed a JSON copy of the token carrying the target’s real user ID as sub, though the forged token had not-a-real-user-id.
While writing this post I re-ran the PoC on the stock 26.7.2 image with JoFlow attached and the user cache, UserCacheSession, added to the classes it watches. My copy of the PoC marks each Acme request from registration onward through /mark, so the trace splits into one window per request.
The forged token again resolved to Bob and the Admin API returned 201. JoFlow logged 8,327 events, including every method call to the watched classes. Figure 4 follows the admin request.
Figure 4. The admin request in the 26.7.2 JoFlow run. Event numbers come from the run’s events.ndjson.
- Jackson parses the forged token into object
o2630. Itssubisnot-a-real-user-idin the decoded JWT, and the snapshot showspreferred_usernamebobwith no session and no roles. lookupUserFromStatelessTokenasks the user cache for the ID insuband gets null, then asks for the username and getso2643. The/objectssnapshot nameso2643as Bob. The grant had issued the token foro2343, Alice’s user (event 6923).resolveLightweightAccessTokenRolesfindso2643again and copies Bob’s ID and roles intoo2630.- Jackson serializes
o2630at event 8242, and itsrealm-managementroles now includerealm-admin. Jackson reads it back as a JSON copy,o2680, at 8253, and the copy’ssubis560b3474-e474-4bb1-987e-9a25b530aeb3, Bob’s ID. JoFlow didn’t watch the caller, but the source shows it isKeycloakIdentity, the identity the admin permission checks use. UsersResource.createUsercreates the user and returns 201.
Step 2 answers the first question: the lookup by sub found nothing, and the lookup by username found Bob. Step 4 explains the JSON copy. Role resolution overwrites the token’s subject with the found user’s ID, in accessToken.subject(userSession.getUser().getId()), so the rest of the request carries the target’s real ID. The next lookup in the request, at event 8262, finds o2643 by sub with no fallback.
The August traces show the same JSON copy with the target’s real ID, and the heap dump from one of those runs holds that ID next to the target’s username and email address.
Each call in the figure also carries provenance from the paper’s walk. The lookup ran in keycloak-services:26.7.2 with an exact match, and the user it returned is a UserAdapter from keycloak-model-infinispan:26.7.2. In the same run, Alice’s own token resolved to her user, o2456, and createUser threw ForbiddenException.
The Fixes in 26.8.2
CVE-2026-92857 closes the registration half. In 26.8.2 the allowed mapper types for registration are the intersection of the policy’s list and a new realm attribute, allowedProtocolMapperTypesForClientAdministrators, which is empty by default. The end of the new getAllowedMapperProviders, from the fix:
1
2
3
4
// Allowed mappers are intersection of the policy configuration and realm attribute. Mapper must be included in both places to be effectively allowed
Set<String> allowedInConfig = new HashSet<>(componentModel.getConfig().getOrDefault(ProtocolMappersClientRegistrationPolicyFactory.ALLOWED_PROTOCOL_MAPPER_TYPES, Collections.emptyList()));
allowedInConfig.retainAll(allowedForAdmins);
return allowedInConfig;
CVE-2026-96447 closes the lookup half. The fix keeps the username fallback only when the token’s client has a pairwise subject mapper that produces the token’s sub from the found user’s ID. The changed branch, trimmed:
1
2
3
4
5
6
7
8
9
10
11
12
13
if (token.getPreferredUsername() != null) {
user = session.users().getUserByUsername(realm, token.getPreferredUsername());
if (user == null) {
return null;
}
if (isPairwiseSubjectMatching(session, realm, user, token)) {
return user;
} else {
logger.warnf("User '%s' found, but not matching with the 'sub' from the token computed for the client '%s'", user.getUsername(), token.getIssuedFor());
return null;
}
}
Red Hat’s description of CVE-2026-96447 uses a different trigger, an old stateless token reaching a service account recreated under the same client ID. It is the same fallback.
26.8.2 also closes the full-scope gap behind Bob’s roles. According to the 26.8.2 upgrade notes, the fix for CVE-2026-109081, which Red Hat describes as a default-roles issue, also adds the “Full Scope Disabled” policy to authenticated registration. A client registered with an Initial Access Token now comes back with fullScopeAllowed off. That is the setting that kept the forged token out of the Admin API in the negative control.
The stock 26.8.2 image stopped the PoC before any of these fixes ran, because of a fourth change. CVE-2026-19688 makes the Admin API require the new kc-admin-api scope, plus the audience that scope adds: the realm’s Admin REST API URL, here https://localhost:19443/admin/realms/acme.
Bob’s setup token came from the JWT grant client without that audience and scope, so creating the Initial Access Token returned 401. An administrator working in the admin console could still create one, because the upgrade assigns the scope to the console’s client.
To test each fix on its own, I set KC_SPI_ADMIN__AUDIENCE_CHECK_ENABLED=false to turn that check off and ran the PoC under JoFlow twice more. Figure 5 shows where each of the three 26.8.2 runs stopped.
Figure 5. Each row is one PoC run on 26.8.2, stopped by the CVE fix named on the left.
With only the audience check off, the trace shows the new allowlist returning an empty set and the policy throwing ProtocolMapper type not allowed, which the client sees as insufficient_scope. For the last run, the master admin also added oidc-usermodel-attribute-mapper to the new realm attribute. Keycloak then issued a token with the same forged sub and preferred_username. The lookup still found Bob, isPairwiseSubjectMatching returned false, and Keycloak logged the warning above. The client in that run also came back without full scope.
Closing Notes
Upgrade to 26.8.2 or 26.6.8, or a later release on those lines. 26.4.17 and 26.4.18 carry only the registration fix, and no 26.7.x release up to 26.7.5 carries either, so a 26.7 install like the one above needs 26.8.2. If you add mapper types to allowedProtocolMapperTypesForClientAdministrators, anyone with an Initial Access Token can shape claims in tokens your services trust. The last run above shows that 26.8.2 still issues a token with the forged claims in that case.
Thanks to Vishal Maurya and Justin Mills. Their paper gave me the idea for JoFlow and its starting point.
JoFlow is one example of building tools as you go. Some of the tools I write only fit the bug in front of me, and others, like JoFlow, carry over to the next target. Agents can run the reproductions and draft the explanation, but knowing the domain is still what tells you whether that explanation holds up.
Maintainers are dealing with a flood of security reports right now. If you report a bug, make sure it’s real, and spend the time to verify it first. For this one, that meant a PoC against the stock image, a negative control, and a JoFlow trace of the objects before the report went out.
If you trace a token through Keycloak a different way, or find a configuration where a patched build still resolves one user’s token to another, I’d like to hear about it.
References
- Keycloak issue #54705. Tracking issue for CVE-2026-92857.
- Keycloak issue #54708. Tracking issue for CVE-2026-96447.
- DCR mapper fix commit. The registration policy change in the 26.8.2 release.
- Username fallback fix commit. The pairwise check in the 26.8.2 release.
- Admin API audience commit. The CVE-2026-19688 change that stops the PoC’s setup on 26.8.2.
- Keycloak 26.8.2 release note. Lists the four CVEs discussed here, among others.
- Keycloak 26.8.2 upgrade notes. The full-scope change for authenticated registration.
- Red Hat CVE-2026-92857. Description and score.
- Red Hat CVE-2026-96447. Description and score.
- Red Hat CVE-2026-19688. Description and score.
- Red Hat CVE-2026-109081. Red Hat’s description, which covers the default-roles half of the fix.
- A Vision for Endpoint-SBOM. Vishal Maurya and Justin Mills, the preprint JoFlow is built on.
- RFC 7523. The JWT bearer grant that Keycloak’s JWT Authorization Grant implements.
- OpenID Connect Core 1.0. Defines
sub,preferred_usernameand the other standard claims. - Keycloak client registration guide. Initial Access Tokens and registration policies.