feat(python): add encode_path_params config to percent-encode path parameters - #17295
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
AI Review Summary
Correctly fixes the missing percent-encoding in encode_path_param and propagates it to all seed fixtures. The implementation matches TS/Go/Java semantics (safe="" ≈ encodeURIComponent). Main concerns are release-note framing (this is behaviorally breaking for APIs with slash-bearing path params) and making sure no other copies of this helper were missed.
- 🟡 1 warning(s)
- 🔵 2 suggestion(s)
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
… config Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Claude Code Review
Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.
Tip: disable this comment in your organization's Code Review settings.
Regenerate the path-parameters fixture via the generator (not hand-copied) into two config folders: - no-custom-config: default output (byte-identical relocation of old root) - encode-path-params: encode_path_params=true, so path params route through quote_path_param() and percent-encode "/" and "..". Covers the flag-on codegen path that previously had no seed snapshot. Co-Authored-By: Claude <noreply@anthropic.com>
…angelog Co-Authored-By: Claude <noreply@anthropic.com>
… in tests Addresses review feedback: assert that every "/" is percent-encoded and that already-encoded input is encoded again (a%2Fb -> a%252Fb). Co-Authored-By: Claude <noreply@anthropic.com>
Description
Refs Auth0 SEC-16202 (Pylon #22523)
Follow-up to #17294 (PHP). While investigating the reported path traversal in the generated PHP SDK,
Python turned out to have the same weakness: generated clients do route path parameters through
encode_path_param, but that helper only stringified the value — it never percent-encoded it. So avalue like
../connectionsstill reaches the URL intact and, once the HTTP client and servernormalize it, the request can resolve to a different endpoint than the method targets.
Changes Made
generators/python/core_utilities/shared/jsonable_encoder.py:encode_path_paramnow returnsquote(str(jsonable_encoder(obj)), safe=""). Booleans keep theirtrue/falserendering.test_encode_path_paramtogenerators/python/tests/sdk/test_jsonable_encoder.py.seed/python-sdkfixtures.generators/python/sdk/changes/unreleased/encode-path-parameters.yml(fix).Behavior note for reviewers: same caveat as the PHP PR — APIs that intentionally accept
slash-containing path parameter values will now send
%2F. This matches TypeScript, Go, Java, andC#, but it is a visible change for existing Python users.
Testing
test_encode_path_param)quote(..., safe="")output for the reported payload(
../connections→..%2Fconnections,user id?→user%20id%3F,user_1→user_1).poetry install/pytestcould not run in this environment (pypi.org is not reachable fromit), so CI is the first full run of the Python test suite for this change.
Update: gated behind
encode_path_params(opt-in)Per review, encoding is now off by default and opted into with a generator config flag:
SDKCustomConfig: newencode_path_params(defaultfalse).encode_path_paramis restored to its original stringify-only behavior; percent-encoding lives in anew
quote_path_paramin the same core utility.CoreUtilities.encode_path_paramemits a call towhichever one the flag selects, so call sites are unchanged.
test_encode_path_param,test_quote_path_param).fix->feat.Caveat, unchanged from before: the
seed/python-sdkfixtures were updated by propagating the coreutility rather than by running python seed (pypi is unreachable from my box, so
poetry installforthe python generator fails). Default output is unchanged, but CI seed is the first real regeneration —
worth a look. There is also no seed fixture exercising the flag on for the same reason.