Repository navigation
fix(typescript,mcp): reject path parameters that form dot segments - #211
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
Generator Snapshot Testing
Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/165#issuecomment-6841576637 Snapshot results are summarized above. Additional run context is linked for maintainers with access. |
There was a problem hiding this comment.
0 issues found across 7 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Bounded security fix: pathToFunc in the TypeScript and MCP templates now rejects path-parameter values that form '.', '..' (including encoded and separator tricks), preventing URL resolution from redirecting credentialed requests; comprehensive tests pin the corrected behavior.
View guided diff | Turn on auto-fix | Re-trigger cubic
ThomasRooney
left a comment
There was a problem hiding this comment.
Approving with nits: the check holds for every parameter style in the generated SDK and MCP server, and output is otherwise identical to main.
- Generated SDKs from main and this head against a local server:
.and..no longer reach a sibling route; dotted values such asa..band.hiddenare still sent. - Generated MCP server, static and dynamic mode:
..returns a tool error and sends nothing. - Evidence: https://app.reflow.io/v1/review-apps/34dea579-7917-4ee5-9db7-322d66bfe6f6/public
(-Thomas + Fable 5.2)
…Error and leave server URLs unchecked
There was a problem hiding this comment.
All reported issues were addressed across 31 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 12 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
Why
Generated TypeScript SDKs build request paths with
pathToFuncand then resolve them against the base URL withnew URL(path, baseURL). Percent-encoding (encodeURIComponent) leaves.unchanged, so a path parameter whose value is exactly.or..becomes a dot segment, and URL resolution removes it along with its parent:The request still carries the client's credentials. If an application passes untrusted input (end-user or model tool-call values) as a path parameter, the input can redirect the call to another endpoint under the same base URL and bypass the per-resource restrictions the application relies on. The flaw is in the shared runtime, so it affects every generated TypeScript SDK and MCP server.
What changed
Operation paths now reject a path parameter value that forms a
.or..segment, before any request is sent. This needs no spec changes.TypeScript SDK: functions with path parameters build the path with a new
encodePathhelper inlib/sdks.ts. A rejected value comes back asERR(InvalidRequestError)through the same invalid-request path as other request-building errors, so standalone functions keep returning aResultand SDK methods reject withInvalidRequestError:MCP server: functions use the same
encodePathhelper, so the function returnsInvalidRequestErroras aResult, the tool call reports an error, and nothing is sent.The check is opt-in on
pathToFunc({ rejectDotSegments: true }) and only operation paths opt in. Server URL templates and server variables are unchanged.The error names the parameters that contributed to the segment:
Parameter 'store_id' must not form a '.' or '..' path segment, orParameters 'a', 'b' ...when several placeholders share it. Placeholders with empty values are not named.The MCP runtime's
pathToFuncnow substitutes hyphenated placeholders such as{thing-blah}, matching the TypeScript runtime. Previously they were left in the path unsubstituted.The check runs per template segment that contains a placeholder, after encoding, and matches what the WHATWG URL parser treats as a dot segment:
.and.., including the percent-encoded forms%2e,.%2E,%2e%2e, etc. (these reachpathToFuncunescaped when a caller pre-encodes or usesallowReserved)/and\(special schemes), soa/../band..\xare caught underallowReserved. Only the part before the first?or#is checked, because the parser ends the path there:..?xis rejected,safe?next=/..is not.\t.would otherwise become..)encodeLabel("."), which renders as..Values that only contain dots remain valid:
...,.hidden,v1.2.3,a..b, and dots next to literal text in the same segment (user-{id}with..givesuser-..). Literal dot segments written into the path template are left untouched.The
zSDKs/sdk-typescriptv2andzSDKs/mcp-typescriptreview SDKs are regenerated.Review notes
fixFlags.encodePathParamsfor new SDKs only). These calls previously reached a different route from the one the caller asked for, so there is no working behaviour to preserve. The changeset calls this out.?or#inside anallowReservedvalue still moves the rest of the URL into the query or fragment, as before. This PR only stops such values from changing the path.Testing
TARGET=primary make test-typescriptv2: 53 files, 852 tests passing.tests/lib/url.test.tscovers rejected forms, encoder output fromencodeSimple/encodeLabel, legitimate dotted values, error wording, and that templates are unchecked withoutrejectDotSegments. A new runtime test checks that a standalone function returnsInvalidRequestError, that the SDK method rejects with it, and that nothing is sent.TARGET=primary make test-mcp-typescript: 33 files, 362 tests passing, including a newtests/lib/url.test.tsfor the MCP runtime (hyphenated placeholders, dot segments, server URL templates) and a runtime test that a function returnsInvalidRequestError.TARGET=review make test-typescriptv2andTARGET=review make test-mcp-typescriptpass.make check-template-typescriptv2andmake check-template-mcp-typescriptpass.make lint: golangci-lint's gofmt check reports an alignment finding on an unrelatedtemplates/perms.goentry; localgofmtmakes no changes to the file.Public-safety check
.claude/skills/public-repo-communication/SKILL.md).git diff --check.Summary by cubic
Blocks path parameter values that form
.or..segments from redirecting SDK requests to a different endpoint under the same base URL.pathToFuncnow rejects them before any request is sent, returning anInvalidRequestErrorin bothtypescriptv2andmcp-typescript; previously the request went to a wrong route.%2e%2e), separators insideallowReservedvalues (a/../b,..\x), and tab/newline tricks that the WHATWG URL parser strips....,.hidden,v1.2.3), dots next to literal text, and literal dot segments written into the path template. Server URL templates are left unchecked.Written for commit 0c7aca9. Summary will update on new commits.