Repository navigation
fix(typescript,mcp): reject path parameters that form dot segments #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TristanSpeakEasy
merged 4 commits into
main
from
fix/typescript-reject-dot-segment-path-params
Nov 16, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fe3895f
fix(typescript,mcp): reject path parameters that form dot segments
TristanSpeakEasy 48162e5
fix(typescript,mcp): only scan the path portion of a parameter for do…
TristanSpeakEasy 628720e
fix(typescript,mcp): return dot-segment path errors as InvalidRequest…
TristanSpeakEasy 0c7aca9
fix(mcp): return dot-segment path errors as InvalidRequestError results
TristanSpeakEasy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| id: 1794462313-1f3dc8f5 | ||
| features: | ||
| - core | ||
| targets: | ||
| - typescriptv2 | ||
| - mcp-typescript | ||
| type: fix | ||
| bump: patch | ||
| description: "behaviour change: operation path parameter values that form . or .. URL segments are now rejected with an InvalidRequestError (an MCP tool error for MCP servers) instead of sending the request to a different route" | ||
| author: TristanSpeakEasy | ||
| date: "2026-11-12" |
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
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
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
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
107 changes: 107 additions & 0 deletions
107
templates/templates/mcp-typescript/tests/lib/url.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
|
|
||
| import { pathToFunc } from "../../lib/url.js"; | ||
|
|
||
| test.each< | ||
| [ | ||
| title: string, | ||
| pattern: string, | ||
| args: Record<string, string | number>, | ||
| output: string | Error, | ||
| ] | ||
| >([ | ||
| ["no placeholders", "/sample/path", {}, "/sample/path"], | ||
| ["one placeholder", "/author/{id}/likes", { id: 123 }, "/author/123/likes"], | ||
| [ | ||
| "infix placeholder", | ||
| "/entity/user-{id}/", | ||
| { id: "1893" }, | ||
| "/entity/user-1893/", | ||
| ], | ||
| [ | ||
| "placeholder with hyphen", | ||
| "/foo/bar/{thing-blah}", | ||
| { "thing-blah": "test-value" }, | ||
| "/foo/bar/test-value", | ||
| ], | ||
| [ | ||
| "insufficient params", | ||
| "/blog/{slug}/comments/{commentId}", | ||
| { slug: "hello-world" }, | ||
| new Error("Parameter 'commentId' is required"), | ||
| ], | ||
| ])("pathToFunc: %s", (_, pattern, args, output) => { | ||
| if (output instanceof Error) { | ||
| expect(() => pathToFunc(pattern)(args)).toThrow(output); | ||
| } else { | ||
| expect(pathToFunc(pattern)(args)).toEqual(output); | ||
| } | ||
| }); | ||
|
|
||
| describe("pathToFunc dot segments", () => { | ||
| const pattern = "/stores/{store_id}/items/{item_id}/details"; | ||
| const dotSegmentError = | ||
| /^Parameter 'store_id' must not form a '\.' or '\.\.' path segment$/; | ||
| const checked = ( | ||
| path: string, | ||
| options?: { charEncoding?: "percent" | "none" }, | ||
| ) => pathToFunc(path, { ...options, rejectDotSegments: true }); | ||
|
|
||
| test.each(["..", ".", "%2e%2e", ".%2E", "a/../b", "..\\b", "..?x", ".\t."])( | ||
| "rejects %j", | ||
| (value) => { | ||
| expect(() => | ||
| checked(pattern)({ store_id: value, item_id: "item-1" }), | ||
| ).toThrow(dotSegmentError); | ||
| }, | ||
| ); | ||
|
|
||
| test.each([".", ".."])("rejects %j under percent encoding", (value) => { | ||
| expect(() => | ||
| checked(pattern, { charEncoding: "percent" })({ | ||
| store_id: value, | ||
| item_id: "item-1", | ||
| }), | ||
| ).toThrow(dotSegmentError); | ||
| }); | ||
|
|
||
| test("rejects dot segments from hyphenated placeholders", () => { | ||
| expect(() => checked("/x/{thing-blah}")({ "thing-blah": ".." })).toThrow( | ||
| /^Parameter 'thing-blah' must not form/, | ||
| ); | ||
| }); | ||
|
|
||
| test("names every placeholder that contributes to the dot segment", () => { | ||
| expect(() => checked("/x/{a}{b}/y")({ a: ".", b: "." })).toThrow( | ||
| "Parameters 'a', 'b' must not form a '.' or '..' path segment", | ||
| ); | ||
| expect(() => checked("/x/{a}{b}/y")({ a: "..", b: "" })).toThrow( | ||
| /^Parameter 'a' must not form/, | ||
| ); | ||
| }); | ||
|
|
||
| test.each(["...", ".hidden", "v1.2.3", "a..b", "safe?next=/.."])( | ||
| "allows %j", | ||
| (value) => { | ||
| expect(checked(pattern)({ store_id: value, item_id: "item-1" })).toEqual( | ||
| `/stores/${value}/items/item-1/details`, | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| test("leaves literal template segments unchanged", () => { | ||
| expect(checked("/v1/../{id}")({ id: "x" })).toEqual("/v1/../x"); | ||
| expect(checked("/entity/user-{id}")({ id: ".." })).toEqual( | ||
| "/entity/user-..", | ||
| ); | ||
| }); | ||
|
|
||
| test("does not check templates unless rejectDotSegments is set", () => { | ||
| expect(pathToFunc("https://{host}/x")({ host: ".." })).toEqual( | ||
| "https://../x", | ||
| ); | ||
| expect(pathToFunc(pattern)({ store_id: "..", item_id: "item-1" })).toEqual( | ||
| "/stores/../items/item-1/details", | ||
| ); | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.