Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/permission/auto-shell-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export const AUTO_SHELL_RULES: AutoShellRule[] = [
// trailing `|` as in `>|` / `>>|`) to a target that is not an fd dup
// (`2>&1`) or a safe pseudo-device (`> /dev/null`, a TTY).
/[0-9]?>>?\|?\s*(?!&|\/dev\/(?:null|stdout|stderr|stdin|tty|pts\/|fd\/))[^\s|;&)]/,
// bash `>& word` is `>word 2>&1` when word is not an fd number or `-`.
// `2>&1` and `n>&-` stay unmatched; `>& /dev/null` stays a safe sink.
/[0-9]?>&\s*(?!(?:[0-9]+|-|\/dev\/(?:null|stdout|stderr|stdin|tty|pts\/|fd\/)\S*)(?:\s|$|[|;&)]))[^\s|;&)]/,
// tee writes its stdin to one or more files.
/(?:^|[\n;&|({]\s*)tee\b/,
// In-place stream editors: sed -i, perl -pi -e, ruby -i.
Expand Down
26 changes: 26 additions & 0 deletions src/permission/classify-security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,32 @@ describe("CL-6702 — bash clobber redirects match file-mutation", () => {
});
});

describe("bash >& file redirects match file-mutation", () => {
test("echo hi >& out.txt denies", () => {
expect(autoShellRuleForCall(shellCall("echo hi >& out.txt"))?.name).toBe(
"file-mutation",
);
});

test("echo hi >&file denies", () => {
expect(autoShellRuleForCall(shellCall("echo hi >&file"))?.name).toBe(
"file-mutation",
);
});

test("echo hi > out.txt still denies", () => {
expect(autoShellRuleForCall(shellCall("echo hi > out.txt"))?.name).toBe(
"file-mutation",
);
});

test("echo hi 2>&1 is not a file-mutation deny", () => {
expect(autoShellRuleForCall(shellCall("echo hi 2>&1"))?.name).not.toBe(
"file-mutation",
);
});
});

describe("CL-6697 — quoted dangerous flags and program names still deny/ask", () => {
test("a quoted -c interpreter one-liner denies", () => {
expect(
Expand Down
Loading