Strip URL hash fragments in static path resolution

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 01:43:59 +00:00
1 parent 4e3b3d0a80
commit 9b3ffaa235
2 files changed
+9 -2

No files matched your search

+8
View File
@@ -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({
+1 -2
View File
@@ -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);