fix: reject empty and dot path segments before building request URLs - #728
Merged
Merged
Conversation
`_encode_path` percent-encodes every segment with `quote(seg, safe="")`,
but `.` is an RFC 3986 unreserved character that `quote` leaves alone, and
httpx applies dot-segment removal when it builds the request URL. A bare
`.` or `..` in a caller-supplied id or slug therefore collapsed the path
onto the parent resource before the request left the process, e.g.
`pipes.delete_user_connected_account(user_id, "..")` was sent as
`DELETE /user_management/users/{user_id}`.
Empty, `.` and `..` are never valid WorkOS identifiers, so the shared
helper now raises `ValueError` for them before any HTTP call. The
docstring no longer claims that quoting alone contains `..`. Every
generated resource routes through this helper, so no regeneration is
needed.
Resolves VULN-1272.
Contributor
|
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.
Description
_encode_pathinsrc/workos/_base_client.py(hand-maintained,@oagen-ignore-file) now raisesValueErrorwhen any path segment is empty,., or... Percent-encoding withsafe=""already contains/,?,#, and%, but.is an RFC 3986 unreserved character thaturllib.parse.quotenever encodes, and httpx applies dot-segment removal when it builds the request URL. A caller-supplied id or slug of..therefore collapsed the path onto the parent resource before the request left the process (for example, disconnecting a connected account became a DELETE of the whole user)...inside its segment.tests/test_generated_client.py: rejection of""/./..for both clients and forbuild_url, encoding of structural characters (a/b→a%2Fb,%2e%2e→%252e%252e,evil/../..stays one segment,...and.hiddenare still accepted), and an end-to-end check thatpipes.delete_user_connected_account(user_id, "..")raises before any HTTP request on both sync and async clients.Every generated resource builds its path as a tuple and routes through this helper, so no regeneration is needed. Supersedes #726, which targeted the
4.xbranch, where this helper does not exist.Resolves VULN-1272.
Compatibility
Path identifiers equal to
"",".", or".."now raiseValueErrorbefore any HTTP request. Such values were never valid WorkOS identifiers; previously they were sent as a request to a different resource. No other input handling changes.Validation
uv run pytest: 2771 passed (2752 baseline + 19 new).uv run ruff format --check .,uv run ruff check,uv run pyright: clean.Documentation
No API reference changes. The behavior change is documented in the helper docstring and the Compatibility section above for release notes.