Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions library/sinks/FileSystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ t.test("it works", async (t) => {
agent.start([new FileSystem()]);

const {
readFile,
writeFile,
writeFileSync,
rename,
Expand Down Expand Up @@ -308,4 +309,28 @@ t.test("it works", async (t) => {
rename(new URL("file:///../../test.txt"), "../test2.txt", () => {});
}
);

runWithContext(
{
remoteAddress: "::1",
method: "POST",
url: "http://localhost:4000",
query: {
q: "file://test/../../../../../../../../../../etc/passwd",
},
headers: {},
body: {},
cookies: {},
routeParams: {},
source: "express",
route: "/posts/:id",
},
() => {
const file = "file://test/../../../../../../../../../../etc/passwd";
throws(
() => readFile(new URL(`file:///public/${file}`)),
"Zen has blocked a path traversal attack: fs.readFile(...) originating from query.q"
);
}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ function isFileUrlString(path: string): boolean {
// oxlint-disable-next-line no-control-regex
.replace(/^[\u0000-\u0020]+/, "")
.toLowerCase()
.startsWith("file:")
.startsWith("file:///")
);
}