Skip to content

Commit 0a38952

Browse files
fix(agents): prevent ReDoS in background-session name derivation
1 parent 6c072b9 commit 0a38952

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/agents/bash-tools.shared.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ describe("deriveSessionName", () => {
133133
expect(deriveSessionName("cmd 'a b\\' next")).toBe("cmd a b\\");
134134
});
135135

136-
it("returns a label without catastrophic backtracking on an unterminated quote followed by backslashes", () => {
137-
const malicious = `node "${"\\".repeat(50000)}`;
138-
const start = process.hrtime.bigint();
139-
const label = deriveSessionName(malicious);
140-
const elapsedMs = Number(process.hrtime.bigint() - start) / 1e6;
141-
expect(typeof label).toBe("string");
142-
expect(elapsedMs).toBeLessThan(100);
136+
it("returns a label without catastrophic backtracking on unterminated quoted backslash runs", () => {
137+
for (const quote of [`"`, `'`]) {
138+
const malicious = `node ${quote}${"\\".repeat(50000)}`;
139+
const start = process.hrtime.bigint();
140+
const label = deriveSessionName(malicious);
141+
const elapsedMs = Number(process.hrtime.bigint() - start) / 1e6;
142+
expect(typeof label).toBe("string");
143+
expect(elapsedMs).toBeLessThan(100);
144+
}
143145
});
144146
});

0 commit comments

Comments
 (0)