Return 404 for missing static assets with extensions
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
9f3f723db8
commit
525c0f6a34
2 files changed
+13
No files matched your search
@@ -449,6 +449,16 @@ describe("resolveStaticAssetReadTarget", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("returns not_found for missing asset files with extensions", () => {
|
||||
const tempDir = mkdtempSync(path.join(os.tmpdir(), "t3-static-missing-asset-"));
|
||||
writeFileSync(path.join(tempDir, "index.html"), "<html>ok</html>", "utf8");
|
||||
|
||||
const result = resolveStaticAssetReadTarget("/assets/missing.js", tempDir);
|
||||
expect(result).toEqual({
|
||||
kind: "not_found",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects symlinked files that escape the dist directory", () => {
|
||||
const tempDir = mkdtempSync(path.join(os.tmpdir(), "t3-static-symlink-"));
|
||||
writeFileSync(path.join(tempDir, "index.html"), "<html>ok</html>", "utf8");
|
||||
|
||||
@@ -505,6 +505,9 @@ export function resolveStaticAssetReadTarget(
|
||||
if (requestedFile.kind === "file") {
|
||||
return requestedFile;
|
||||
}
|
||||
if (path.extname(requestedPath.filePath).length > 0) {
|
||||
return { kind: "not_found" };
|
||||
}
|
||||
|
||||
const indexPath = path.join(normalizedDistRoot, "index.html");
|
||||
const indexFile = resolveSafeFilePathInDist(indexPath, realDistRoot);
|
||||
|
||||
Reference in new issue
Block a user