Keycloak Login Page Stored XSS, Fixed in 26.8.2 (CVE-2026-107889)
A realm admin's stored JavaScript runs on Keycloak's login page because a URL fix-up step undoes sanitizer encoding; fixed in 26.8.2.
TL;DR
- A realm administrator with
manage-realmcan store a link whosejavascript:scheme is hidden as a numeric character reference. Keycloak's URL fix-up step decodes it after sanitization, so it runs in visitors' browsers. Red Hat published CVE-2026-107889 on 2026-10-09. - Keycloak 26.1.3 through 26.8.1 is affected. The community fix is 26.8.2; the 26.6 backport is tagged 26.6.8 and ships in Red Hat build of Keycloak 26.6.8. Red Hat Single Sign-On 7 is not affected.
- Red Hat, the CVE Numbering Authority, scores it CVSS v3.1 5.5 Medium with CWE-79. No public exploit has been reported, and the CVE is not in CISA KEV as of 2026-11-20.
- Upgrade to 26.8.2. Red Hat build of Keycloak users on 26.6 need 26.6.8. Red Hat lists no supported workaround; see "How do I fix it?" for interim containment.
Am I affected?
You are affected if your realm runs an affected release, renders its display name HTML through kcSanitize, and lets someone with manage-realm change that setting.
- The Keycloak or Red Hat build of Keycloak release is affected according to the version table.
- The realm's login theme passes
realm.displayNameHtmlthroughkcSanitize. The built-inbaseandkeycloak.v2themes do. - At least one person or group with
manage-realmcan change the realm settings. A delegated realm administrator, a stolen administrator session or an insider meets this condition. - Users load that realm's login page in a browser.
The flaw is a privilege boundary problem. manage-realm is already a powerful permission, but it should not give its holder script execution in other users' browsers. A realm whose only manage-realm holders are fully trusted is less exposed, but a stolen administrator session is enough.
The upstream issue records the affected range as 26.1.3 through 26.8.0. Release 26.8.1, published before the backport, carries the same code. Keycloak published 26.8.2 as the community fix and tagged the 26.6 backport as 26.6.8. The 26.7 line and older branches carry the same code and have no fixed release, so deployments on them must move to 26.8.2.
| Branch | Affected versions | Fixed version |
|---|---|---|
| Keycloak 26.8 | 26.8.0 to 26.8.1 | 26.8.2 (released 2026-11-05) |
| Keycloak 26.6 | 26.6.0 to 26.6.7 | No community release; the 26.6.8 tag carries the backport. Move to 26.8.2 |
| Keycloak 26.7 | 26.7.0 to 26.7.5 | No fixed release; move to 26.8.2 |
| Keycloak 26.1.3 to 26.5.x | affected per the upstream issue | No fixed release; move to 26.8.2 |
| Red Hat build of Keycloak 26.6 | affected | 26.6.8 (RHSA-2026:95761, issued 2026-11-06) |
| Red Hat Single Sign-On 7 | not affected | not applicable |
Check the running version on the host and inside every container:
/opt/keycloak/bin/kc.sh --version
docker ps --format '{{.Image}}' | grep -i keycloak
docker exec <container-name> /opt/keycloak/bin/kc.sh --version
kubectl get deploy -A -o jsonpath='{..image}' | tr ' ' '\n' | grep -i keycloak
Then list the display name HTML of every realm with the admin CLI:
/opt/keycloak/bin/kcadm.sh config credentials \
--server https://keycloak.example.com --realm master --user admin
/opt/keycloak/bin/kcadm.sh get realms --fields realm,displayNameHtml
A realm with no displayNameHtml value does not use the field. A value that contains &# deserves a close look, because that is the encoding the bypass needs.
How do I fix it?
Upgrade to Keycloak 26.8.2, released on 2026-11-05. That is the community release with the fix. The 26.6 backport is tagged 26.6.8 and ships in Red Hat build of Keycloak 26.6.8.
- For a container deployment, pull the fixed image and recreate the container. A running container keeps its old image until it is recreated.
bash docker pull quay.io/keycloak/keycloak:26.8.2 docker compose up -d --force-recreate keycloak - For Kubernetes, update the image and wait for the rollout:
bash kubectl set image deployment/<deployment> <container>=quay.io/keycloak/keycloak:26.8.2 kubectl rollout status deployment/<deployment> - For a ZIP installation, download
keycloak-26.8.2.zipfrom the release page. Back up the configuration and the database, then replace the installation. - For Red Hat build of Keycloak, update to 26.6.8 from RHSA-2026:95761 for the server packages or RHSA-2026:95762 for the OpenShift images. The fixed image tags are
26.6-24. - Deployments on 26.7 or an older branch must move to 26.8.2, because those branches have no fixed release.
Red Hat lists no mitigation that meets its product security criteria, and the CVE record says the same. If you cannot upgrade yet, these measures reduce exposure but do not fix the flaw:
- Clear
displayNameHtmlon every realm and review it again regularly:bash /opt/keycloak/bin/kcadm.sh update realms/<realm> -s displayNameHtml='' - Reduce the set of accounts and groups that hold
manage-realm, and review that set for unexpected grants. - Enable admin events on the master realm and any realm with delegated administration, so a later change to the realm settings leaves a record.
An attacker who still holds manage-realm can store the payload again after any of these steps. Clearing the field removes only the payloads that are already stored.
What is the root cause?
The sanitizer approves a URL it reads as relative, and a later fix-up restores the character reference that turns it into a javascript: URL. kcSanitize is a FreeMarker method that Keycloak themes call with ?no_esc to render administrator-supplied HTML after cleaning it.
The login page reads realm.displayNameHtml and passes it to that method. The built-in theme does it in themes/src/main/resources/theme/base/login/template.ftl at line 105:
<div id="kc-header-wrapper"
class="${properties.kcHeaderWrapperClass!}">${kcSanitize(msg("loginTitleHtml",(realm.displayNameHtml!'')))?no_esc}</div>
The method is KeycloakSanitizerMethod, in services/src/main/java/org/keycloak/theme/KeycloakSanitizerMethod.java. At release 26.8.0 it runs three steps in sequence:
String html = list.get(0).toString();
html = decodeHtmlFull(html);
String sanitized = KeycloakSanitizerPolicy.POLICY_DEFINITION.sanitize(html);
return fixURLs(sanitized);
decodeHtmlFull calls the OWASP Java HTML Sanitizer's Encoding.decodeHtml up to five times. The sanitizer then applies KeycloakSanitizerPolicy. That policy allows href on a elements when the value matches an on-site or off-site URL pattern, and it enables allowStandardUrlProtocols():
.allowAttributes("href").matching(ONSITE_OR_OFFSITE_URL)
.onElements("a")
.allowStandardUrlProtocols()
The on-site pattern is the part that matters:
private static final Pattern ONSITE_URL = Pattern.compile(
"(?:[\\p{L}\\p{N}\\\\\\.\\#@\\$%\\+&;\\-_~,\\?=/!]+|\\#(\\w)+)");
ONSITE_URL accepts letters, digits, &, ;, #, =, ? and other characters, but it does not require a colon. The value javascript:alert(xss) has no literal colon, so it matches the relative-URL pattern. The protocol policy only filters values that carry a scheme, so it never sees javascript. The sanitizer serializes the value with the ampersand escaped as &, which keeps the reference inert in the served page.
The last step, fixURLs, repairs links after sanitization:
private String fixURLs(String msg) {
Matcher matcher = HREF_PATTERN.matcher(msg);
if (matcher.find()) {
int last = 0;
StringBuilder result = new StringBuilder(msg.length());
do {
String href = matcher.group(1).replaceAll("=", "=")
.replaceAll("\\.\\.", ".")
.replaceAll("&", "&");
result.append(msg.substring(last, matcher.start(1))).append(href);
last = matcher.end(1);
} while (matcher.find());
result.append(msg.substring(last));
return result.toString();
}
return msg;
}
HREF_PATTERN matches every href="..." in the sanitized markup. The three replacements decode = to =, collapse .. to ., and turn & back into &. The last replacement removes the exact encoding the sanitizer used to keep the character reference inert. The output carries href="javascript:alert(xss)", and the browser decodes : to : when it parses the attribute. The link now targets a javascript: URL.
fixURLs rewrites every link after sanitization: it decodes =, collapses .. and restores &. Those repairs assume the value is a URL the sanitizer already approved. The two stages disagree about which representation is authoritative: the sanitizer checks one form, and the post-processor serves another.
How is it exploited?
A user with manage-realm stores a crafted link in the realm's display name HTML. A visitor loads the login page, and activating the link runs its script in the Keycloak origin. The fix commit's tests use this payload:
<a href="javascript:alert(xss)">link</a>
- The attacker sends
PUT /admin/realms/<realm>withdisplayNameHtmlset to the payload. The admin console exposes the same field under the realm's display name settings. - Keycloak stores the string in the realm configuration. The admin API accepts HTML in this field by design, so no validation rejects the encoded colon.
- A visitor loads the realm's login page. The theme passes the stored value to
kcSanitize. decodeHtmlFullleaves the reference encoded because it has no semicolon. The sanitizer sees no literal colon, treats the value as a relative URL and allows it, then escapes the ampersand.fixURLsreplaces&with&. The served page carrieshref="javascript:alert(xss)".- The browser decodes the numeric reference and the link targets
javascript:alert(xss). Activating the link runs the script in the Keycloak origin.
The upstream issue describes the impact as requiring no interaction beyond loading the page, and it records a no-click variant on the WebAuthn error page. The fix's tests cover the display-name link. The public record does not include the WebAuthn payload, so this post does not reconstruct that variant.
Red Hat's CVSS vector marks UI:N. Treat the issue's no-click statement as part of the record rather than as a detail these steps prove.
How does the attack flow?
A realm administrator stores a link whose colon is entity-encoded. The sanitizer approves it as a relative URL, and the URL fix-up restores the reference that makes it executable.
displayNameHtml payload"] --> B["kcSanitize decodes
and runs the sanitizer"] B --> C["No literal colon:
treated as relative URL"] C --> D["Sanitizer escapes &
payload stays inert"] D --> E["fixURLs restores &
after the check"] E --> F["Browser decodes :
and sees javascript:"] F --> G["Script runs in
the Keycloak origin"]
What can an attacker do?
The attacker can run JavaScript in the Keycloak origin in the browser of a user who loads the realm's login page.
Every condition has to hold:
- The attacker holds
manage-realmfor the target realm, through a delegated role, a stolen session or insider access. - The realm runs an affected release and uses a theme that renders
displayNameHtmlthroughkcSanitize. - A user loads that realm's login page in a browser.
- For the display-name link in the fix's tests, the user activates the link. The upstream issue records a no-click variant on the WebAuthn error page, and Red Hat's vector marks
UI:N.
The script runs in the Keycloak origin, not in the application that uses Keycloak as its identity provider. In that origin it can do three things:
- Read what the user types into the login form before the form is submitted.
- Replace the form with one that posts credentials to another host.
- Rewrite the page into a phishing prompt.
It can also send same-origin requests, which carry the user's Keycloak cookies even when those cookies are HttpOnly. It cannot read an HttpOnly cookie value directly.
Red Hat scores the flaw CVSS v3.1 5.5 with CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:L/I:L/A:N. PR:H reflects the manage-realm requirement. S:C reflects that the script crosses from an administrator-controlled setting into other users' browsers. C:L and I:L record limited read and write impact on the login page rather than on the Keycloak server.
Why does the fix work?
The fix re-checks each href after the fix-up replacements, in the decoded form the browser will see, and empties any value whose scheme is not http, https or mailto. The new check sits between the replacements and the output:
String href = matcher.group(1).replaceAll("=", "=")
.replaceAll("\\.\\.", ".")
.replaceAll("&", "&");
+ if (hasDisallowedScheme(href)) {
+ href = "";
+ }
result.append(msg.substring(last, matcher.start(1))).append(href);
hasDisallowedScheme decodes numeric character references before it asks the OWASP URL policy whether the value is allowed:
private boolean hasDisallowedScheme(String href) {
return URL_PROTOCOL_POLICY.apply("a", "href", decodeNumericEntities(href)) == null;
}
The policy is built with the three schemes the login page needs:
private static final FilterUrlByProtocolAttributePolicy URL_PROTOCOL_POLICY =
new FilterUrlByProtocolAttributePolicy(List.of("http", "https", "mailto"));
For javascript:alert(xss), decodeNumericEntities produces javascript:alert(xss), the policy rejects the javascript scheme, and the attribute becomes href="". Relative URLs still pass, because they carry no scheme, and links with http, https or mailto are unchanged.
The tests in the same commit cover decimal, hexadecimal, zero-padded, mixed-case, newline and tab forms of the reference, plus vbscript and data schemes. They also check that bold text, http, https and mailto links survive. The fix closes the numeric-reference path this CVE describes. It does not remove HTML from displayNameHtml, and it does not change the rest of the sanitizer policy, so the field remains an administrator-controlled HTML surface.
How do I check if I was compromised?
No public indicators of compromise have been published, so the reliable check is the stored realm configuration itself. A payload that was never activated leaves its string in displayNameHtml, and the browser decodes that string into a javascript: URL.
List every realm's display name HTML and look for the encoding the bypass needs:
/opt/keycloak/bin/kcadm.sh get realms --fields realm,displayNameHtml | grep -n '&#'
Then inspect the values that matched. A legitimate display name can contain a numeric reference, such as ' for an apostrophe. Look for a reference in an href, especially one that decodes to :.
If admin events are enabled, review realm update events for changes you cannot explain:
/opt/keycloak/bin/kcadm.sh get admin-events -r <realm> \
--query operationTypes=UPDATE --query resourceTypes=REALM
The event record shows who changed the realm and when, provided admin events were on before the change. A realm that never enabled them has no history to review.
Reverse-proxy logs can show that a login page was served, but they cannot show whether a stored link was activated. A payload that ran in a browser may leave no trace on the server. No vendor signature or log pattern has been published for this CVE.
Timeline
- 2026-10-08: Reported to Red Hat and made public, per the CVE record.
- 2026-10-09: Red Hat publishes the CVE record, and the upstream issue is opened.
- 2026-10-13: Fix commit
3e0fda9lands on the main branch. - 2026-10-14: The 26.8 and 26.6 backports are merged.
- 2026-11-05: Keycloak 26.8.2 is released.
- 2026-11-06: Red Hat issues RHSA-2026:95761 and RHSA-2026:95762 for Red Hat build of Keycloak 26.6.8.
FAQ
Does an unauthenticated attacker exploit this?
No. The attacker needs manage-realm on the target realm before any user can be exposed. The realistic paths are a malicious delegated administrator, a stolen administrator session or an insider. Every visitor of that realm's login page is then in scope.
Does the victim have to click the link?
For the display-name payload, yes: the fix's tests store an anchor, and a browser runs a javascript: URL when the link is activated. The upstream issue records a no-click variant on the WebAuthn error page, and Red Hat's vector marks UI:N. Treat a visit to an affected realm's login page as exposure rather than relying on users not to click.
Are custom themes affected?
Only when the theme renders displayNameHtml through kcSanitize. The built-in base and keycloak.v2 themes do. A custom theme that does not render the field is outside this path, and a theme that renders it without kcSanitize has a different problem.
Is 26.6.8 enough for the 26.6 line?
For Red Hat build of Keycloak, yes: 26.6.8 contains the backport merged on 2026-10-14. Keycloak published no community 26.6.8 release, so community deployments on 26.6 should move to 26.8.2. Deployments on 26.7 or older must also move to 26.8.2.
Is Red Hat Single Sign-On 7 affected?
No. The CVE record lists Red Hat Single Sign-On 7 as unaffected. Red Hat build of Keycloak 26.6 is affected and is fixed in 26.6.8.
Was it exploited in the wild?
No. The CISA Authorized Data Publisher entry records exploitation as none, and the CVE is not in CISA KEV as of 2026-11-20. The fix's tests publish payload shapes, so the technique is public even though no working exploit has been reported.
Test Keycloak login pages with Ostorlab
Ostorlab's Web Agentic Deep Scan exercises authentication pages and the fields they render, including stored cross-site scripting. You can assess a Keycloak login page before a stored payload reaches users: see how Web Agentic Deep Scan works.
References
- CVE record CVE-2026-107889, published 2026-10-09. https://www.cve.org/CVERecord?id=CVE-2026-107889 (checked November 20, 2026)
- Red Hat CVE page for CVE-2026-107889. https://access.redhat.com/security/cve/CVE-2026-107889 (checked November 20, 2026)
- Red Hat Bugzilla 2548355, the private report migrated to the public tracker. https://bugzilla.redhat.com/show_bug.cgi?id=2548355 (checked November 20, 2026)
- Red Hat errata RHSA-2026:95761, "Red Hat build of Keycloak 26.6.8 Security Update", issued 2026-11-06. https://access.redhat.com/errata/RHSA-2026:95761 (checked November 20, 2026)
- Red Hat errata RHSA-2026:95762, "Red Hat build of Keycloak 26.6.8 Images Security Update", issued 2026-11-06. https://access.redhat.com/errata/RHSA-2026:95762 (checked November 20, 2026)
- Keycloak issue 53813, "[CVE-2026-107889] Stored XSS on the login page via kcSanitize bypass", opened 2026-10-09. https://github.com/keycloak/keycloak/issues/53813 (checked November 20, 2026)
- Fix commit 3e0fda9765c4b911c2d79c65549115c0b4e643fb, "prevent kcSanitize from re-activating disallowed URL schemes after link fixup", 2026-10-13. https://github.com/keycloak/keycloak/commit/3e0fda9765c4b911c2d79c65549115c0b4e643fb (checked November 20, 2026)
- Backport pull request 53969 for the 26.8 branch, merged 2026-10-14. https://github.com/keycloak/keycloak/pull/53969 (checked November 20, 2026)
- Keycloak 26.8.2 release, published 2026-11-05. https://github.com/keycloak/keycloak/releases/tag/26.8.2 (checked November 20, 2026)
- Keycloak 26.6.8 tag. https://github.com/keycloak/keycloak/tree/26.6.8 (checked November 20, 2026)
- KeycloakSanitizerMethod.java at release 26.8.0. https://github.com/keycloak/keycloak/blob/26.8.0/services/src/main/java/org/keycloak/theme/KeycloakSanitizerMethod.java (checked November 20, 2026)
- KeycloakSanitizerPolicy.java at release 26.8.0. https://github.com/keycloak/keycloak/blob/26.8.0/services/src/main/java/org/keycloak/theme/KeycloakSanitizerPolicy.java (checked November 20, 2026)
- Login template at release 26.8.0. https://github.com/keycloak/keycloak/blob/26.8.0/themes/src/main/resources/theme/base/login/template.ftl (checked November 20, 2026)
- CISA Known Exploited Vulnerabilities catalog, version 2026.11.20. https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json (checked November 20, 2026)