Repository navigation
Decode \uXXXX escapes in SCIM filter string values - #52298
amdadulbari wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Adds correct decoding of \uXXXX Unicode escapes in SCIM filter string values by updating FilterUtils.unescapeJsonString, correcting its Javadoc, and adding regression tests to prevent reintroducing the issue.
Changes:
- Decode
\uXXXXescapes inFilterUtils.unescapeJsonStringwhile leaving malformed sequences literal. - Update Javadoc to reflect that ANTLR recognizes but does not decode Unicode escapes.
- Add regression tests covering valid, mixed, and malformed Unicode escape cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| scim/core/src/main/java/org/keycloak/scim/filter/FilterUtils.java | Implements \uXXXX decoding in unescapeJsonString and updates Javadoc to match actual lexer behavior. |
| scim/core/src/test/java/org/keycloak/scim/filter/FilterUtilsTest.java | Adds regression tests ensuring \uXXXX escapes are decoded (and malformed ones remain literal). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| case 'u' -> { | ||
| int cp = -1; | ||
| if (i + 4 < s.length()) { | ||
| try { | ||
| cp = Integer.parseInt(s, i + 1, i + 5, 16); | ||
| } catch (NumberFormatException ignored) { | ||
| // not four hex digits - leave the escape literal | ||
| } | ||
| } | ||
| if (cp >= 0) { | ||
| sb.append((char) cp); | ||
| i += 4; | ||
| } else { | ||
| sb.append('\\').append(next); | ||
| } | ||
| } |
There was a problem hiding this comment.
FIx makes sense to me, CI failures are not related
4e7acc4 to
4d9c541
Compare
|
Rebased to re-trigger CI that got stalled. |
New input from copilot for parser problem
|
@amdadulbari / @sguilhen - the copilot comment seems valid; the parser should be strict. Please verify. |
4d9c541 to
b987ec9
Compare
|
@ahus1 Thanks, agreed - the parser should be strict. |
| assertEquals("\\u\u0660\u0660\u0664\u0661", FilterUtils.unescapeJsonString("\\u\u0660\u0660\u0664\u0661")); | ||
| assertEquals("\\u004G", FilterUtils.unescapeJsonString("\\u004G")); | ||
| // end-to-end: a filter comparison value carrying a \\uXXXX escape | ||
| assertDoesNotThrow(() -> FilterUtils.parseFilter("userName eq \"\\u0041\"")); |
There was a problem hiding this comment.
Seems legit and worth fixing, IMO: parseFilter never invokes the decoder, so this only proves the grammar accepts the escape, not that it's actually decoded through extractCompValue.
FilterUtils.unescapeJsonString decoded every JSON escape except the \uXXXX form, whose default switch arm left it untouched. So the escape for U+0041 stayed as its six literal characters (backslash, u, 0, 0, 4, 1) instead of becoming "A". The Javadoc claimed Unicode escapes were handled by the ANTLR lexer, but the lexer only recognizes \uXXXX (a grammar fragment) and does not decode it - getText() returns the raw source. As a result a filter comparing against a \uXXXX escape compared against those literal characters and never matched the intended value. Decode \uXXXX like the other escapes, and correct the Javadoc. The four hex digits are validated strictly as ASCII [0-9A-Fa-f] before parsing, since Integer.parseInt also accepts a leading sign and non-ASCII Unicode digits; any escape that is not followed by four ASCII hex digits is left literal. Add regression coverage for Unicode escapes, including interleaving with other escapes, mixed-case hex digits and malformed escapes (too few digits, a sign, non-ASCII digits, non-hex characters). Closes keycloak#52295 Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>
b987ec9 to
b75d41e
Compare


Closes #52295
FilterUtils.unescapeJsonStringdecoded every JSON escape except the\uXXXXform, whosedefaultarm left it literal - so the escape forU+0041stayed as its six characters instead of becomingA. The Javadoc claimed the ANTLR lexer handled Unicode escapes, but the lexer only recognizes\uXXXX(a grammar fragment) and returns the raw text viagetText().Decode
\uXXXXlike the other escapes (a malformed escape without four hex digits is left literal), and correct the Javadoc.Added regression coverage in
FilterUtilsTest, verified fails-before / passes-after.