Skip to content

Commit 8528f1b

Browse files
committed
Fix multiple control chars
1 parent 583ab84 commit 8528f1b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

library/sinks/FileSystem.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,34 @@ t.test("it works", async (t) => {
249249
}
250250
);
251251

252+
runWithContext(
253+
{
254+
remoteAddress: "::1",
255+
method: "POST",
256+
url: "http://localhost:4000",
257+
query: {
258+
q: ".\t\t./etc/passwd",
259+
},
260+
headers: {},
261+
body: {},
262+
cookies: {},
263+
routeParams: {},
264+
source: "express",
265+
route: "/posts/:id",
266+
},
267+
() => {
268+
throws(
269+
() =>
270+
rename(
271+
new URL("file:///.\t\t./etc/passwd"),
272+
"../test123.txt",
273+
() => {}
274+
),
275+
"Zen has blocked a path traversal attack: fs.rename(...) originating from query.q"
276+
);
277+
}
278+
);
279+
252280
// Ignores malformed URLs
253281
runWithContext(
254282
{ ...unsafeContext, body: { file: { matches: "../%" } } },

library/vulnerabilities/path-traversal/containsUnsafePathParts.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ t.test("it detects dangerous path parts for URLs", async () => {
4040
t.same(containsUnsafePathPartsUrl("file:///.\t./test.txt"), true);
4141
t.same(containsUnsafePathPartsUrl("file://.\n./test.txt"), true);
4242
t.same(containsUnsafePathPartsUrl("file://.\r./test.txt"), true);
43+
t.same(containsUnsafePathPartsUrl("file:///.\t\t./test.txt"), true);
44+
t.same(containsUnsafePathPartsUrl("file:///.\t\n./test.txt"), true);
4345
});
4446

4547
t.test("it only removes some chars from the URL", async () => {
@@ -51,4 +53,6 @@ t.test("it only removes some chars from the URL", async () => {
5153
t.same(fileURLToPath("file:///.\v./test.txt"), "/.\v./test.txt");
5254
t.same(fileURLToPath("file:///.\f./test.txt"), "/.\f./test.txt");
5355
t.same(fileURLToPath("file:///.\b./test.txt"), "/.\b./test.txt");
56+
t.same(fileURLToPath("file:///.\t\t./test.txt"), "/test.txt");
57+
t.same(fileURLToPath("file:///.\t\n./test.txt"), "/test.txt");
5458
});

library/vulnerabilities/path-traversal/containsUnsafePathParts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export function containsUnsafePathParts(filePath: string) {
2020
* See https://url.spec.whatwg.org/#url-parsing
2121
*/
2222
export function containsUnsafePathPartsUrl(filePath: string) {
23-
return /(?:\.(?:\t|\n|\r)?){2}(?:\/|\\)/.test(filePath);
23+
return /(?:\.(?:\t|\n|\r)*){2}(?:\/|\\)/.test(filePath);
2424
}

0 commit comments

Comments
 (0)