Repository navigation
fix(client): URL-encode path parameters and reject empty, '.' and '..' (#4) - #8
Merged
Merged
Conversation
#4) Add a private `_seg()` helper in `_http.py` and route every caller-supplied value interpolated into a URL path through it, in both the sync and async clients (26 sites each). It percent-encodes the value as exactly one path segment (`quote(str(value), safe="")`) and raises ValueError before any request is sent for "", "." and "..", matching the TypeScript SDK contract. The parity guard unwraps `{_seg(x)}` to `{x}` so manifest path templates are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Independent review (OpenAI-family lane, different model family from the implementer) at exact head
Nits (non-blocking, follow-up): the new matrix omits a PUT route ( GitHub CI: |
TARSDrakon
added a commit
that referenced
this pull request
Oct 17, 2026
Brings in PR #8 (path-parameter encoding). CHANGELOG.md conflict in [Unreleased] resolved by keeping both entries under one "Fixed" heading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
Closes #4
Lockstep twin of the TypeScript SDK path-parameter fixes (shieldcortex-sdk #5, #7, #10).
What changed
_seg(value) -> strinsrc/shieldcortex/_http.py: returnsurllib.parse.quote(str(value), safe=""), and raisesValueErrorbefore any request is sent whenstr(value)is""(path parameter must not be empty) or"."/".."(path parameter must not be '.' or '..').client.pyandasync_client.pynow goes through_seg(). Ids that were valid before keep the same URL. The only difference is that reserved characters (/,?,#,%, space, non-ASCII) are now percent-encoded.tests/test_parity.pynormaliser unwraps{_seg(x)}→{x}, so the manifest path templates inendpoint_manifest.pyare unchanged.[Unreleased]→### Fixedentry.Sites changed (26 per client, identical in
client.pyandasync_client.py)/v1/audit/{id}/v1/quarantine/{id}/v1/quarantine/{id}/review/v1/keys/{id}/v1/invites/{id}/v1/invites/{id}/resend/v1/devices/{uuid}/v1/alerts/{id}/v1/webhooks/{id}/v1/webhooks/{id}/test/v1/webhooks/{id}/deliveries/v1/firewall-rules/{id}/v1/iron-dome/patterns/{id}/v1/iron-dome/patterns/{id}/test/v1/iron-dome/policies/{id}/v1/iron-dome/policies/{id}/default/v1/verify/{id}/v1/audit/exports/{manifest_id}/v1/audit/exports/{manifest_id}/verify/v1/audit/exports/{manifest_id}/verificationsThat makes 52 sites in total, which is every match of
rg -n 'f"/v1/[^"]*\{' src/shieldcortex.Sites deliberately left
url = f"{self._base_url}{path}"in the five_raw_*request helpers of each client: this joins the configured base URL with an already-built path. No caller-supplied segment is involved.pagination.pyandintegrations/(langchain.py,crewai.py) build no URL paths. They only call public client methods, which are now encoded.+concatenation,.format()or%. Query strings go through httpxparamsand are out of scope.Tests added (
tests/test_path_params.py)_segunit cases: plain, int,a/b?c#d→a%2Fb%3Fc%23d,50% off→50%25%20off,café→caf%C3%A9, anda..b/.hiddenunchanged."",.and..raise./,?and#stays one encoded segment (checked viaurl.raw_path, with an empty query) on GET, POST, PATCH and DELETE routes. An audit-export manifest id with a space,/and non-ASCII characters is encoded."","."and".."raiseValueErroron GET, POST, PATCH and DELETE routes, with no request made (respx.calls.call_count == 0).a..band.hiddenare accepted and sent unchanged.Gate receipts (run by the author of this PR)
python3 -m venv …→ exit 0pip install -e '.[dev,langchain]'→ exit 0python -m pytest -q→ exit 0,182 passedruff check src tests/test_path_params.py tests/test_parity.py→ All checks passed.ruff check testsstill reports 6 F401/I001 errors intests/test_client.pyandtests/test_types.py, which were there before this PR and are untouched.mypy src→ Success: no issues found in 12 source files🤖 Generated with Claude Code