Post

CVE-2026-103112: Racing Password Reset into Account Takeover in Keycloak

How an ordinary Keycloak user races two requests on one active code to move their own login result onto another account, and the flow-membership check that closes it.

CVE-2026-103112: Racing Password Reset into Account Takeover in Keycloak

Disclaimer. This is an authorized write-up of a bug that is already fixed. Every request below went to a stock Keycloak container bound to 127.0.0.1, against throwaway accounts in a disposable realm. Nothing here points at a live system. Run a patched release.

Table of Contents

  1. Introduction
  2. Where the Two Flows Cross
  3. Racing One Active Code
  4. The Token Comes Back as Alice
  5. The Fix
  6. Closing Notes
  7. References

Introduction

TL;DR CVE-2026-103112 lets an ordinary Keycloak user with a password-only account take over another account without the target’s password or OTP, in a realm with Forgot Password enabled. The attacker submits their own password to the password-reset endpoint, which marks the attacker’s login form as passed and returns a Choose User page whose form carries a one-time code. Two requests that reuse that code then race, and in the right order the target replaces the attacker as the session’s user while that mark stays. The fix checks that each submitted login step belongs to the flow being run.

I started looking at Keycloak’s password-reset flow after CVE-2026-18963, which let an unauthenticated attacker skip that flow’s email verification and set a new password on any account. I then used my harness to check Keycloak for similar bugs.

This story has two users of the same Keycloak realm. Mallory is the attacker. She has an ordinary account that logs in with a password, and no OTP. Alice is the target. Her account is protected by a password and an OTP code.

Mallory doesn’t know Alice’s password and can’t produce her OTP code. All she needs is her own password and Alice’s email address. The realm also has Forgot Password enabled, which is off in a new realm. By the end, Mallory holds an access token issued for Alice, and Alice has done nothing at all.

The attack below ran on Keycloak 26.7.3. The Keycloak issue labels CVE-2026-103112 high severity and carries fix labels for 26.4.17, 26.6.8, 26.8.2 and 27.0.0. Red Hat’s entry scores it 7.5 under CVSS 3.1.

Where the Two Flows Cross

Keycloak runs browser login and password reset as separate authentication flows. The browser flow’s forms subflow contains the username-and-password form and conditional second-factor checks. The reset flow begins with Choose User, which asks for a username or email address. Each form action carries an execution ID for its step. In our run, the two forms had different IDs and posted to /login-actions/authenticate and /login-actions/reset-credentials, respectively.

Mallory starts a browser login with kc_action=UPDATE_PASSWORD, requesting a password-update action after authentication. Keycloak returns the username-and-password form. She keeps its session cookie and server-issued query parameters, changes only the action path to /login-actions/reset-credentials, and submits her own username and password. The reset endpoint now receives an execution ID from the browser flow.

On 26.7.3, the reset endpoint accepts that browser-flow execution. It validates Mallory’s password and skips the OTP form because her account has no OTP credential. Keycloak records the browser forms subflow as SUCCESS and renders the reset flow’s Choose User page.

The authentication session now holds Mallory as its current user alongside that browser-flow result. Setting a different user while Mallory is still set raises USER_CONFLICT. Clearing the current user is allowed, though, and leaves the forms result in place. That is the state the race exploits.

Racing One Active Code

Mallory needs two requests to put Alice on that session while keeping the saved forms result:

  • Clear Mallory. Post a nonexistent username to /login-actions/reset-credentials. When Keycloak accepts it, clearUser() removes Mallory as the current user but leaves forms marked SUCCESS.
  • Bind Alice. Post Alice’s email address to /login-actions/authenticate. If the clear has taken effect, Keycloak can select Alice while the browser forms result remains SUCCESS.

Both requests use Mallory’s authentication-session cookie and the query values from the Choose User form’s action URL, including the same session_code and execution. The clear follows the form’s reset path; the bind changes that path to /authenticate. The shared execution still identifies Choose User in the reset flow, yet 26.7.3 accepts it at /authenticate. On the successful bind, Keycloak resumes browser login with Alice selected and goes to UPDATE_PASSWORD without asking for her password or OTP.

The controls show why the requests must overlap. A bind without a clear returned HTTP 400. In a sequential attempt, the clear produced the email confirmation, but the bind using the same session_code then got “Page has expired”. The PoC therefore sends the two branches in bursts while the Choose User action is active.

For each burst, it prepared 64 clears and 64 binds, opened their connections, and sent every request except the final byte of its form body. It then released those bytes in pairs, flipping which branch went first each time. The winning run used no timing offset. This excerpt is trimmed from the PoC; the comments explain the held byte and release order:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class PendingRequest:
    def __init__(self, label, url, username, cookie, proxy):
        # ... URL parsing, form body and raw HTTP headers cut ...

        # Open the connection and disable Nagle so it does not delay small writes.
        self.sock = socket.create_connection((connect_host, connect_port), timeout=30)
        self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        # Send the headers and the whole body except its last byte.
        # Holding that byte leaves the form body incomplete.
        self.sock.sendall(head + self.body[:-1])
        self.response = b""

    # Send the held-back byte, which completes the request.
    def release(self):
        self.sock.sendall(self.body[-1:])

    # ... receive() and write() cut: they read and save each response ...


cookie = cookies_from(cookie_file)
proxy = proxy_from(proxy_value)
# Build both branches up front. Every request reuses Mallory's cookie
# and the same active code.
clears = [PendingRequest("clear", clear_url, clear_username, cookie, proxy) for _ in range(count)]
binds = [PendingRequest("target-bind", bind_url, bind_username, cookie, proxy) for _ in range(count)]

# Pick the release order. The winning run used the default, alternating.
if release_order == "clear-first":
    requests = clears + binds
elif release_order == "bind-first":
    requests = binds + clears
else:
    # Interleave the pairs, flipping which branch goes first each time.
    requests = []
    for index, pair in enumerate(zip(clears, binds)):
        clear, bind = pair
        requests.extend((bind, clear) if index % 2 == 0 else (clear, bind))

# Release every final byte back to back. This is the race.
for index, request in enumerate(requests):
    request.release()
    # Optional delay between releases. It was 0 in the winning run, so it never ran.
    if skew_us and index + 1 < len(requests):
        deadline = time.perf_counter_ns() + skew_us * 1000
        while time.perf_counter_ns() < deadline:
            pass

The second burst advanced the flow. Three clear responses contained “You should receive an email shortly”, and one bind redirected to UPDATE_PASSWORD. These crops show an accepted clear and the successful bind from that burst.

Raw Burp request and response showing the accepted clear's confirmation text Accepted clear. The submitted form was username=as21-stock-user-that-does-not-exist. The raw response contains the email confirmation. Sensitive request values are redacted in black; the shared code’s prefix remains visible.

The bind capture shows the other branch of the same burst.

Raw Burp request and response for the successful target bind in the winning burst Target bind. The submitted form was username=as21-stock-otp-target%40example.invalid. The raw response returned 302 to /login-actions/required-action?execution=UPDATE_PASSWORD. Sensitive request and response values are redacted the same way.

The Token Comes Back as Alice

The redirect alone would leave room to argue about which user owned the session, so I followed it to the end. I set a new password for Alice, took the authorization code, exchanged it at the token endpoint, and decoded the access token. The endpoint returned HTTP 200. The token’s sub matched Alice’s user ID.

A fresh login with the replacement password was accepted and stopped at Alice’s OTP step, and Alice’s original password was rejected. OTP was configured on the account before and after the takeover. The forged session never had to pass it.

The Fix

The fix changes AuthenticationProcessor.authenticationAction. The old code reset the flow only when the submitted execution ID did not exist, and never checked which flow it belonged to. The patch adds that check through a new checkExecutionBelongsToFlow helper:

1
2
3
4
5
6
if (model == null || !AuthenticatorUtil.checkExecutionBelongsToFlow(realm, flowId, model)) {
    logger.debug("Cannot find execution in the authentication flow, reseting flow");
    logFailure(null);
    resetFlow();
    return authenticate();
}

The check runs before Keycloak processes the submitted form. The password step in Mallory’s first post belongs to the browser flow, so it fails the check at the reset endpoint. Keycloak never evaluates her password there, and the forms subflow never records SUCCESS. Keycloak calls resetFlow instead, which sets the authenticated user to null and clears every step result on the session. It then calls authenticate(), which starts the reset flow from its first step.

On 26.8.2, Mallory’s first post still landed on a Choose User page, and the PoC did not produce a takeover.

The commit’s regression test switches the login URL to the reset-credentials path, then checks that returning to the original login URL lands on the page-expired screen.

Closing Notes

Upgrade to 26.8.2, 26.6.8 or 26.4.17, or a later release on those lines. No 26.7.x release up to 26.7.5 carries the fix, so a 26.7 install like the one above needs 26.8.2. Until you can upgrade, Red Hat’s CVE page offers courtesy guidance, which it notes was AI-generated, with two stopgaps: turn off Forgot Password, or require a second factor for every user in the realm. Red Hat adds that these limit exposure but don’t fix the underlying defect.

If you test a build for this, follow the chain to the token and compare its sub with the target’s user ID. If you find a timing or configuration where a patched build still mixes the two flows, I’d like to hear about it.

References

This post is licensed under CC BY 4.0 by the author.