fix(scim): return 400 for malformed startIndex and count - #1007
Open
omlahore wants to merge 1 commit into
Open
Conversation
_list_users and _list_groups parsed the SCIM pagination parameters with a bare int(), so any non-integer value from the client raised ValueError and surfaced as a 500. A negative count was worse: it reached the queryset as qs[offset : offset + count] and Django rejects a negative slice bound with ValueError too. Both now go through parse_pagination_params, which reports a bad value as a SCIM 400 with scimType=invalidValue, clamps startIndex to 1 and a negative count to 0 per RFC 7644 section 3.4.2.4. views/audit.py already guarded its int() calls this way; this brings the SCIM endpoints in line.
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.
Both SCIM list endpoints parse their pagination parameters with a bare
int():ee/authentication/scim/views/users.py:138andviews/groups.py:235. Those values come straight from the SCIM client, nothing upstream catchesValueError, and the result is a 500.Three ways in:
The third one is the least obvious. A negative count survives
min(-5, 100)and reaches the queryset asqs[offset : offset + count], andQuerySet.__getitem__rejects a negative slice bound.This matters a bit more than a normal 400/500 mixup because the caller is an IdP. Okta and Entra treat a 5xx as a transient provisioning failure and retry it, where a 400 tells them the request itself is wrong.
The change
Both call sites go through a new
parse_pagination_paramsinscim/utils.py. It returns a SCIM 400 withscimType=invalidValuefor a non-integer, clampsstartIndexto 1 and a negativecountto 0, per RFC 7644 section 3.4.2.4.I did not invent the shape of any of this.
views/audit.py:83-90already wraps the same twoint()calls intry/except (ValueError, TypeError), and_list_usersalready returnsscim_invalid_filter(...)two lines below for a bad filter. This just applies the handling that is already there to the parameters that were missed.Tests
backend/tests/ee/authentication/scim/test_pagination_params.py, 13 cases: defaults, valid values, non-integerstartIndexandcountacross several shapes, the clamp to 1, the negative count, and the cap atSCIM_DEFAULT_COUNT.pytest tests/ee/authentication/scim/is 200 passed, so nothing regressed.On CI
The image build job will go red on this the way it does on my other PRs.
docker/login-actiongetsSecret source: Noneon fork PRs and fails before any build step. The frontend and backend test jobs are the ones that matter here, and this change is backend only.