Fix NPE in SCIM PATCH when request body contains "schemas": null#51173
Open
sergioperezcheco wants to merge 1 commit into
Open
Fix NPE in SCIM PATCH when request body contains "schemas": null#51173sergioperezcheco wants to merge 1 commit into
sergioperezcheco wants to merge 1 commit into
Conversation
ScimResourceTypeResource.patch() calls request.getSchemas().contains() without a null check. When a client sends a PATCH request body with "schemas": null, Jackson overwrites the default Set.of(SCHEMA) initializer in PatchRequest with null, and the .contains() call throws a NullPointerException resulting in HTTP 500 instead of a proper 400 Bad Request. Add a null check so a missing schemas set is treated the same as a schemas set without the PATCH op schema, returning invalidSyntax (400). Adds a test that sends a PATCH with a null schemas set and asserts the 400 response. Fixes keycloak#51156 Signed-off-by: sergioperezcheco <checo520@outlook.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents SCIM PATCH requests with null schemas from causing HTTP 500 errors.
Changes:
- Adds null-safe PATCH schema validation.
- Adds regression coverage for null schemas.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
ScimResourceTypeResource.java |
Returns invalid-syntax HTTP 400 for null schemas. |
UserTest.java |
Adds regression test, but serialization omits the null field. |
| PatchRequest request = PatchRequest.create() | ||
| .add("active", "false") | ||
| .build(); | ||
| request.setSchemas(null); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Sending a SCIM PATCH request whose body explicitly sets "schemas": null causes a NullPointerException and an HTTP 500 instead of the expected 400. Jackson deserializes the field as null, overwriting the default Set.of(SCHEMA) initializer in PatchRequest, and ScimResourceTypeResource.patch() then calls request.getSchemas().contains(Scim.PATCH_OP_CORE_SCHEMA) on the null set.
This adds a null check so a missing schemas set is treated identically to a schemas set lacking the PATCH op schema — both return invalidSyntax (400). Added a test that issues a PATCH with a null schemas set and asserts the 400 response.
Fixes #51156