From 9b3ffaa2354fde708a556a1740930bb799e4455a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 01:43:59 +0000 Subject: [PATCH] Strip URL hash fragments in static path resolution Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 8 ++++++++ apps/t3/src/cli.ts | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index f4cc245782..fca42bcfcd 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -517,6 +517,14 @@ describe("resolveStaticAssetPath", () => { }); }); + it("strips hash fragments when resolving request paths", () => { + const result = resolveStaticAssetPath("/assets/main.js#chunk", distRoot); + expect(result).toEqual({ + kind: "file", + filePath: path.join(distRoot, "assets", "main.js"), + }); + }); + it("rejects traversal attempts with decoded dot-dot segments", () => { const result = resolveStaticAssetPath("/../package.json", distRoot); expect(result).toEqual({ diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index 275421e193..0bdc264c5c 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -464,8 +464,7 @@ export function resolveStaticAssetPath( requestUrl: string | undefined, distRoot: string, ): { kind: "file"; filePath: string } | { kind: "forbidden" } | { kind: "bad_request" } { - const pathWithoutQuery = requestUrl ? requestUrl.split("?")[0] : "/"; - const rawPath = pathWithoutQuery || "/"; + const rawPath = requestUrl ? (requestUrl.split(/[?#]/, 1)[0] ?? "/") : "/"; let decodedPath: string; try { decodedPath = decodeURIComponent(rawPath);