From 2d7754c19fec2c242d52f48a710c417229ebd254 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 02:17:34 +0000 Subject: [PATCH] Handle absolute-form static request targets safely Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 15 +++++++++++++++ apps/t3/src/cli.ts | 19 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index 0214e11702..951917cda6 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -695,6 +695,21 @@ describe("resolveStaticAssetPath", () => { }); }); + it("supports absolute-form request targets by using URL pathname", () => { + const result = resolveStaticAssetPath("http://127.0.0.1/assets/main.js?x=1", distRoot); + expect(result).toEqual({ + kind: "file", + filePath: path.join(distRoot, "assets", "main.js"), + }); + }); + + it("rejects malformed absolute-form request targets", () => { + const result = resolveStaticAssetPath("http://%zz", distRoot); + expect(result).toEqual({ + kind: "bad_request", + }); + }); + 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 5bf5d83a43..11231a9357 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -515,7 +515,24 @@ export function resolveStaticAssetPath( requestUrl: string | undefined, distRoot: string, ): { kind: "file"; filePath: string } | { kind: "forbidden" } | { kind: "bad_request" } { - const rawPath = requestUrl ? (requestUrl.split(/[?#]/, 1)[0] ?? "/") : "/"; + const rawPath = (() => { + if (!requestUrl) { + return "/"; + } + + if (requestUrl.startsWith("http://") || requestUrl.startsWith("https://")) { + try { + return new URL(requestUrl).pathname; + } catch { + return null; + } + } + + return requestUrl.split(/[?#]/, 1)[0] ?? "/"; + })(); + if (!rawPath) { + return { kind: "bad_request" }; + } let decodedPath: string; try { decodedPath = decodeURIComponent(rawPath);