Handle absolute-form static request targets safely
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
1345ec325a
commit
2d7754c19f
2 files changed
+33
-1
No files matched your search
+18
-1
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user