Amazon Ergo 1.0 · Balanced

add-html-sanitizer-for-translated-message-resources-keycloak

Keycloak · Java · M · 100–299 lines · 6 files

The normal review, with one generalist agent. Judge: Claude Opus 5.5.

Gold bugs found
2 of 7
Comments published
3
Comments matching a bug
2
Comments not matching
1
Cost of this PR
$4.188

Published comments (3)

criticalsecuritymisc/theme-verifier/src/main/java/org/keycloak/themeverifier/VerifyMessageProperties.java:124-126

HTML in choice alternatives bypasses sanitization — Markup hidden inside a `{n,choice,...}` alternative is replaced with `...` by `normalizeValue()` before sanitization, so payloads such as `onerror=alert(1)` pass while remaining in the raw message. Sanitize the alternative text, or strip only the choice syntax while retaining its content.

highbugmisc/theme-verifier/src/main/java/org/keycloak/themeverifier/VerifyMessageProperties.java:74-75

Fallback regex misses numeric locale regions, validating file against itself — A numeric locale such as `messages_es_419.properties` resolves `englishFile` to itself, so values are validated against themselves and `santizeAnchors()` trusts the file's own anchors, allowing arbitrary anchor HTML. Include numeric region codes in the fallback suffix pattern or use locale-aware fallback resolution.

mediumbugthemes/src/main/resources-community/theme/base/account/messages/messages_lt.properties:101

Lithuanian totpStep1 message contains Italian text — Users selecting Lithuanian now see an Italian instruction. Restore `totpStep1` with a Lithuanian translation instead of the copied string. **Also found in:** - `themes/src/main/resources-community/theme/base/login/messages/messages_lt.properties:71-71`

Gold bugs found (2)

mediumThe Lithuanian TOTP setup step was replaced with Italian text in both the account and login bundles.
highnormalizeValue blanks the entire choice expression for some keys before HTML validation, so markup placed inside a choice branch of those keys bypasses the new verifier.

Gold bugs missed (5)

mediumThe diff-trimming code computes common prefix and suffix independently, so they can overlap and substring throws StringIndexOutOfBoundsException, crashing the verifier instead of reporting the illegal HTML.
mediumThe account and admin UI bundles now use Java MessageFormat placeholders and choice syntax for error-invalid-multivalued-size, but i18next expects {{n}}, so the UI shows literal {0}/{1}/{2} and the raw choice text.
mediumThe anchor regex </?a[^>]*> in the theme verifier treats any tag starting with 'a' (<abbr>, <area>, ...) as an anchor tag, which can produce misleading anchor errors or strip such tags before HTML sanitizing.
mediumThe illegalHtmlTag fixture uses a malformed '</div' closing tag, so the sanitizer flags it for malformation and verifyIllegalHtmlTagDetected would still pass if <div> were permitted by POLICY_SOME_HTML; the test does not isolate the forbidden-tag check.
mediumsantizeAnchors removes matching opening anchor tags without checking that the translation keeps the matching closing </a> (or the same number of anchors), so a translation with an unclosed <a ...> passes verification and renders a link that swallows the following content.