Strip URL hash fragments in static path resolution
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
4e3b3d0a80
commit
9b3ffaa235
2 files changed
+9
-2
No files matched your search
@@ -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
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user