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);