You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resolve SCIM PATCH value filters on any sub-attribute - #55611
Microsoft Entra ID changes a user's email with a replace on emails[type eq "work"].value (Microsoft's SCIM tutorial, "Update User [Multi-valued properties]"). RFC 7644 §3.5.2 allows a value selection filter on any sub-attribute of a multi-valued attribute, so this is a valid request. Keycloak turns the filter into the value to remove, which only works for value, and answers 400 invalidSyntax. Entra then resends the refused change in every later PATCH for that user. When the user is unassigned, Entra sends active false in the same PATCH as the pending email change, and the whole PATCH fails. A user whose email ever changed in Entra can then never be disabled by Entra.
Decisions
A filter that names a sub-attribute other than value is matched against the entries the resource holds now, through the new Path.select. This applies only to a complex multi-valued attribute of the core schema that is returned by default, which today means a user's emails. An attribute returned only on request, such as a group's members, keeps the existing value-only handling, so a filtered remove never reads every member of a large group.
A filter on value alone, such as members[value eq "<id>"], takes the existing path unchanged, so member removals by id behave as before.
A filter that matches no current value fails remove and replace with 400 noTarget (RFC 7644 §3.5.2.2, §3.5.2.3 and §3.12), and nothing changes. Carrying on is not safe here. The email remover clears the email whatever entries it is given, and add ignores the filter, so replace emails[type eq "home"].value would overwrite the user's only email. A new ScimNoTargetException is mapped to this error in Error.
A filter naming a sub-attribute the complex type does not have, such as emails[kind eq "work"], still answers 400, now with "Unknown attribute kind". A typo is reported instead of being treated as "no match". Nested value filters are refused the same way.
The matcher supports eq, ne, co, sw, ew and pr, combined with and, or and not. On a boolean sub-attribute such as primary, only eq and ne apply, and only with true or false. gt, ge, lt and le on a string answer 400. The whole filter is checked before any entry is compared, so an invalid branch of an or is refused too.
String comparisons ignore case, because type, display and value of the core multi-valued attributes are not case exact in RFC 7643.
Not changed
add with a filtered path still ignores the filter. Entra sends a user's first email as an add with the same path, and that already worked. A user still has one email, which Keycloak reports as type: work.
Review focus
AbstractModelSchema.remove and selectsByCurrentEntries, which decide when a filter is matched against the current entries, Path.select, the private validate that checks the whole filter first, and the private ScimFilterEntryMatcher in Path, which compares one entry with the filter, and the noTarget mapping in Error.
Before the fix, with only the new tests applied: ./mvnw -pl scim/tests/base test -Dtest=UserTest fails only testPatchReplace, at the first filtered replace emails[type eq "work"].value, which main refuses with 400 invalidSyntax.
After the fix, with the distribution rebuilt from this branch (quarkus/dist, which the test server is unpacked from): ./mvnw -pl scim/core,scim/tests/base test passes, with 62 unit tests and 313 integration tests (2 skipped, both already @Disabled), including UserTest 111 (2 skipped) and PathTest 11/11.
The first version of this change, on 26.8.2, was run against Microsoft Entra ID's provisioning service on 27 November, using provision on demand. Entra created the user (201). It changed the email with the filtered Replace (200). On unassignment it sent one PATCH with active and the filtered email Replace together (200), and the user was disabled with the new email. Entra writes op names capitalised, and it sent active as the string "False", not the boolean the tutorial shows. Both are already accepted.
AI assistance: this change was prepared with Claude Code, an AI coding agent. I have reviewed it and will handle the review.
Microsoft Entra ID changes a user's email with a filtered replace such
as emails[type eq "work"].value. The filter is now resolved against the
current values of the attribute, so it can select on any sub-attribute
of a core complex multi-valued attribute, not only value.
A filter that matches no current value returns 400 noTarget (RFC 7644
sections 3.5.2.2, 3.5.2.3 and 3.12) instead of falling through to the
add half of a replace, which would overwrite a value the filter did not
select.
Closeskeycloak#55607
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Prasad Rahatekar <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
SCIM PATCH filtering can accept invalid operators and delete email entries instead of returning 400, while stale-state and case-sensitive lookups also reject valid operations.
This PR extends Keycloak’s SCIM PATCH handling to support email filters such as emails[type eq "work"].value, addressing Microsoft Entra ID provisioning failures that can block email updates and account disabling.
Changes:
Matches non-value filters against current entries for eligible core attributes, while preserving existing value-only handling.
Returns 400 noTarget when a filtered remove or replace finds no matching entry.
Adds unit and integration coverage for email selection, rejected filters, and combined email/deactivation requests.
The filter in a path such as emails[type eq "work"].value is now checked
once, before any entry is compared. Each sub-attribute must be one of
the complex type's, matched ignoring case (RFC 7643 section 2.1), each
operator must apply to the sub-attribute's type, so a boolean such as
primary takes only eq and ne, and nested value filters are refused.
Before, these checks ran only while matching an entry, so an "or" or
"and" could skip an invalid branch, and a filter on an attribute with
no entries was never checked at all.
Closeskeycloak#55607
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Prasad Rahatekar <[email protected]>
The operations of one PATCH request apply in sequence (RFC 7644 section
3.5.2). A filter was matched against the resource read before the
request, so it did not see what an earlier operation of the same
request changed. A remove of emails followed by a filtered replace of
the email went through instead of answering noTarget.
The current entries are now read from the model, which holds the
changes of the earlier operations.
Closeskeycloak#55607
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Prasad Rahatekar <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Invalid boolean comparisons and nested filters can still cause unintended email deletion or overwriting, while the leaver test does not verify an actual active-to-inactive transition.
Checking only the operator lets remove emails[primary ne "abcde"] match the stored primary: true and delete the email instead of rejecting an invalid boolean comparison. Validate non-null boolean operands as true/false before matching, as ScimJPAPredicateProvider.parseBoolean already does.
A nested filter such as emails[value[value eq "[email protected]"]].value contributes only value names here, so filtersOnlyOnValue() returns true and bypasses the new nested-filter rejection. The legacy converter then ignores the nesting, allowing a remove or replace to clear or overwrite the email; reject value-path nodes during classification so these invalid paths cannot reach that fallback.
This user was already disabled by the earlier PATCH (lines 1071–1078), so the new leaver test still passes if the combined request ignores its active operation. Reactivate the user and assert that state before this PATCH so the test verifies an actual true-to-false transition.
A boolean sub-attribute such as primary is now compared only with true
or false, so emails[primary ne "abcde"] answers 400 instead of
selecting the email. A nested value filter such as
emails[value[value eq "..."]] is no longer treated as a filter on
value, which would have ignored the nesting, and is refused.
The leaver test now switches the user on before the combined request,
so it checks that active changes from true to false.
Closeskeycloak#55607
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Prasad Rahatekar <[email protected]>
The SCIM error mapper uses a ModelValidationException message as a
MessageFormat pattern. Putting the value from the filter into the
message itself let a value such as "{" break the pattern and turn the
intended 400 into a 500. The value is now a parameter of the message.
Closeskeycloak#55607
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Prasad Rahatekar <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed to evaluate a subtle SCIM path-matching issue where Unicode-escaped operands cause valid paths to return noTarget for existing values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #55607
Why
Microsoft Entra ID changes a user's email with a
replaceonemails[type eq "work"].value(Microsoft's SCIM tutorial, "Update User [Multi-valued properties]"). RFC 7644 §3.5.2 allows a value selection filter on any sub-attribute of a multi-valued attribute, so this is a valid request. Keycloak turns the filter into the value to remove, which only works forvalue, and answers 400invalidSyntax. Entra then resends the refused change in every later PATCH for that user. When the user is unassigned, Entra sendsactivefalse in the same PATCH as the pending email change, and the whole PATCH fails. A user whose email ever changed in Entra can then never be disabled by Entra.Decisions
valueis matched against the entries the resource holds now, through the newPath.select. This applies only to a complex multi-valued attribute of the core schema that is returned by default, which today means a user'semails. An attribute returned only on request, such as a group'smembers, keeps the existingvalue-only handling, so a filtered remove never reads every member of a large group.valuealone, such asmembers[value eq "<id>"], takes the existing path unchanged, so member removals by id behave as before.removeandreplacewith 400noTarget(RFC 7644 §3.5.2.2, §3.5.2.3 and §3.12), and nothing changes. Carrying on is not safe here. The email remover clears the email whatever entries it is given, andaddignores the filter, soreplace emails[type eq "home"].valuewould overwrite the user's only email. A newScimNoTargetExceptionis mapped to this error inError.emails[kind eq "work"], still answers 400, now with "Unknown attribute kind". A typo is reported instead of being treated as "no match". Nested value filters are refused the same way.eq,ne,co,sw,ewandpr, combined withand,orandnot. On a boolean sub-attribute such asprimary, onlyeqandneapply, and only withtrueorfalse.gt,ge,ltandleon a string answer 400. The whole filter is checked before any entry is compared, so an invalid branch of anoris refused too.type,displayandvalueof the core multi-valued attributes are not case exact in RFC 7643.Not changed
addwith a filtered path still ignores the filter. Entra sends a user's first email as anaddwith the same path, and that already worked. A user still has one email, which Keycloak reports astype: work.Review focus
AbstractModelSchema.removeandselectsByCurrentEntries, which decide when a filter is matched against the current entries,Path.select, the privatevalidatethat checks the whole filter first, and the privateScimFilterEntryMatcherinPath, which compares one entry with the filter, and thenoTargetmapping inError.Local validation (main 8590b1b)
./mvnw -pl scim/tests/base test -Dtest=UserTestfails onlytestPatchReplace, at the first filtered replaceemails[type eq "work"].value, which main refuses with 400invalidSyntax.quarkus/dist, which the test server is unpacked from):./mvnw -pl scim/core,scim/tests/base testpasses, with 62 unit tests and 313 integration tests (2 skipped, both already@Disabled), includingUserTest111 (2 skipped) andPathTest11/11../mvnw -Pspotless spotless:check -pl scim/core,scim/model,scim/services,scim/tests/basepasses.Tested with Microsoft Entra ID
The first version of this change, on 26.8.2, was run against Microsoft Entra ID's provisioning service on 27 November, using provision on demand. Entra created the user (201). It changed the email with the filtered
Replace(200). On unassignment it sent one PATCH withactiveand the filtered emailReplacetogether (200), and the user was disabled with the new email. Entra writes op names capitalised, and it sentactiveas the string"False", not the boolean the tutorial shows. Both are already accepted.AI assistance: this change was prepared with Claude Code, an AI coding agent. I have reviewed it and will handle the review.