Skip to content

Commit efe7cc7

Browse files
oss-contribremote-controlled-man
authored andcommitted
fix(runtime): enforce basePath segment boundary in single-route mode
1 parent 5eec9b0 commit efe7cc7

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎packages/runtime/src/v2/runtime/__tests__/single-route-resource-operations.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,17 @@ test("single-route resource errors report the matched resource path", async () =
395395
}),
396396
);
397397
});
398+
399+
test("single-route 404s when the path shares only a string prefix with basePath", async () => {
400+
const { handler } = setup();
401+
402+
const response = await handler(
403+
new Request("https://example.com/api/copilotkit-extra", {
404+
method: "POST",
405+
headers: { "Content-Type": "application/json" },
406+
body: JSON.stringify({ method: "info" }),
407+
}),
408+
);
409+
410+
expect(response.status).toBe(404);
411+
});

‎packages/runtime/src/v2/runtime/core/fetch-handler.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,16 @@ async function resolveSingleRoute(
762762
basePath.length > 1 && basePath.endsWith("/")
763763
? basePath.slice(0, -1)
764764
: basePath;
765-
if (!pathname.startsWith(normalizedBase)) {
766-
throw jsonResponse({ error: "Not found" }, 404);
765+
// Same boundary rule as multi-route matchRoute: "/" matches everything;
766+
// otherwise the character after basePath must be "/" or end of string.
767+
if (normalizedBase !== "/") {
768+
const afterBase = pathname.slice(normalizedBase.length);
769+
if (
770+
!pathname.startsWith(normalizedBase) ||
771+
(afterBase.length > 0 && !afterBase.startsWith("/"))
772+
) {
773+
throw jsonResponse({ error: "Not found" }, 404);
774+
}
767775
}
768776
}
769777

0 commit comments

Comments
 (0)