Skip to content

Commit 3b776cf

Browse files
committed
fix(permissions): keep scanning after a temp-only rm -rf
A later dangerous command in the same Bash call must still ask.
1 parent 6cc80a4 commit 3b776cf

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎packages/agent-core-v2/src/agent/permissionPolicy/policies/dangerous-command-ask.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,17 @@ function analyzeSource(
204204
if (!parsed.ok || parsed.hasError) return { kind: 'unanalyzable' };
205205
const commands: BashSyntaxNode[] = [];
206206
collectCommands(parsed.root, commands);
207+
const tempOperands: string[] = [];
207208
for (const command of commands) {
208209
const verdict = analyzeCommand(command, depth, parse);
209-
if (verdict !== undefined) return verdict;
210+
if (verdict === undefined) continue;
211+
if (verdict.kind === 'temp-rm') {
212+
tempOperands.push(...verdict.operands);
213+
continue;
214+
}
215+
return verdict;
210216
}
217+
if (tempOperands.length > 0) return { kind: 'temp-rm', operands: tempOperands };
211218
return undefined;
212219
}
213220

‎packages/agent-core-v2/test/agent/permissionPolicy/permissionPolicyService.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ describe('AgentPermissionPolicyService chain', () => {
286286
['systemctl --user reboot', 'systemctl reboot'],
287287
['bash -c "shutdown now"', 'shutdown'],
288288
['rm -rf /tmp/build /root', 'rm -rf'],
289+
['rm -rf /tmp/build && rm -rf /root', 'rm -rf'],
289290
['rm -rf /tmp/../etc', 'rm -rf'],
290291
['rm -rf /tmpfoo', 'rm -rf'],
291292
['rm -fr dir', 'rm -rf'],
@@ -324,7 +325,12 @@ describe('AgentPermissionPolicyService chain', () => {
324325
});
325326
});
326327

327-
it.each(['rm -rf /tmp/build', 'rm -rf /temp/cache', 'rm -rf -- /tmp/build'])(
328+
it.each([
329+
'rm -rf /tmp/build',
330+
'rm -rf /temp/cache',
331+
'rm -rf -- /tmp/build',
332+
'rm -rf /tmp/build && rm -rf /temp/cache',
333+
])(
328334
'approves `%s` in yolo mode',
329335
async (command) => {
330336
mode = 'yolo';

0 commit comments

Comments
 (0)