fix: reject cmd.exe caret and control chars; fix subprocess lifecycle bugs in runIngest

This commit is contained in:
meels
2026-07-28 14:34:43 +02:00
parent 79d3240aa2
commit fa1e14c8d1
2 changed files with 73 additions and 26 deletions

View File

@@ -26,6 +26,14 @@ test("isSafeFilename rejects shell metacharacters", () => {
}
});
test("isSafeFilename rejects the cmd.exe escape character and control characters", () => {
// `^` escapes the next character in cmd.exe, so it can defuse the closing
// quote. NUL additionally makes spawn() throw synchronously.
for (const bad of ["a^b.md", "a\u0000b.md", "a\u001bb.md", "a\u007fb.md"]) {
assert.equal(isSafeFilename(bad), false, `should reject: ${JSON.stringify(bad)}`);
}
});
test("isSafeFilename rejects path traversal", () => {
assert.equal(isSafeFilename("../secrets.md"), false);
assert.equal(isSafeFilename("a/../../b.md"), false);