feat(php): add encode-path-params config to percent-encode path parameters - #17294
Merged
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2 tasks
Contributor
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 |
…nfig Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…elog Co-Authored-By: Claude <noreply@anthropic.com>
iamnamananand996
approved these changes
Jul 31, 2026
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
Refs Auth0 SEC-16202 (Pylon #22523)
The PHP SDK generator interpolated path parameter values straight into the path template
(
path: "/users/{$id}"), so a value could inject its own separators. Reported and verified live byAuth0's security team:
users->get('../connections')buildsusers/../connections, which normalizesto a different Management API endpoint than the method targets — bounded only by the token's scopes.
This cannot be fixed in
RawClient::buildUrl(): by thenBaseApiRequest::$pathis one assembledstring, so the template's separators and value-supplied separators are indistinguishable. Encoding
must happen where the value is substituted, i.e. in the emitted client code.
TypeScript (
encodeURIComponent), Go (url.PathEscape), Java (OkHttpaddPathSegment) and C#(
Uri.EscapeDataString) already encode path params; this brings PHP in line.Changes Made
generators/php/sdk/src/core/RawClient.ts:getPathStringnow returns an AST node that emits"/users/" . RawClient::encodePathParam($id)instead of"/users/{$id}", keeping literal/separators unencoded (and dropping the interpolatable-vs-concatenated special case, since every
value now goes through a call).
generators/php/base/src/asIs/Client/RawClient.Template.php: newRawClient::encodePathParam()—rawurlencodefor scalars/stringables,true/falsefor bools,''for null, JSON for anythingelse.
testEncodePathParam/testEncodedPathParamDoesNotTraverseto the generatedRawClientTest.seed/php-sdk.generators/php/sdk/changes/unreleased/encode-path-parameters.yml(fix).Behavior note for reviewers: any API that intentionally accepts slash-containing path parameter
values (file-path-like ids) will now send
%2F. That is the same behavior as the other generators,but it is a visible change for existing PHP users — flagging in case you want it gated.
The Python generator is affected too (
encode_path_paramstringifies but does not percent-encode);that fix is going out in a separate PR.
Testing
RawClientTestcases;pnpm turbo run test --filter @fern-api/php-sdkpasses)seed test --generator php-sdk --local --skip-scripts: 155/155 fixtures pass; verifiedencodePathParamoutput withphplocally (../connections→..%2Fconnections,42→42,true→true,null→'').Update: gated behind
encode-path-params(opt-in)Per review, encoding is now off by default and opted into with a generator config flag, so no
existing PHP SDK user's output changes until they enable it:
SdkCustomConfig: newencode-path-params(defaultfalse).RawClient.getPathStringkeeps the previous unencoded interpolation path when the flag is off, andemits
"/users/" . RawClient::encodePathParam($id)when on.RawClient::encodePathParam()isalways present in the generated core.
seed/php-sdk/path-parameters/encode-path-paramscovering the flag; allother fixtures are byte-identical to
mainagain.fix->feat.Reseed:
156/156php-sdk seed fixtures pass;pnpm turbo run test --filter @fern-api/php-sdkgreen.Flipping the default later should go through
packages/generator-migrationsper CLAUDE.md.