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
24 changes: 24 additions & 0 deletions packages/core/src/policy/policy-engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,30 @@ describe('PolicyEngine', () => {
expect(result.decision).toBe(PolicyDecision.ALLOW);
});

it('should NOT downgrade to ASK_USER for redirected commands in YOLO mode even without sandbox', async () => {
const rules: PolicyRule[] = [
{
toolName: 'run_shell_command',
decision: PolicyDecision.ALLOW,
priority: 10,
},
];

engine = new PolicyEngine({
rules,
approvalMode: ApprovalMode.YOLO,
sandboxManager: new NoopSandboxManager(),
});

const command = 'npm test 2>&1 | tail -80';
const { decision } = await engine.check(
{ name: 'run_shell_command', args: { command } },
undefined,
);

expect(decision).toBe(PolicyDecision.ALLOW);
});

it('should return ALLOW in YOLO mode even if shell command parsing fails', async () => {
const { splitCommands } = await import('../utils/shell-utils.js');
const rules: PolicyRule[] = [
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/policy/policy-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,11 @@ export class PolicyEngine {
if (allowRedirection) return false;
if (!hasRedirection(command)) return false;

// Do not downgrade (do not ask user) if sandboxing is enabled and in AUTO_EDIT or YOLO
const sandboxEnabled = !(this.sandboxManager instanceof NoopSandboxManager);
// Do not downgrade (do not ask user) if in AUTO_EDIT or YOLO mode.
// These modes trust the agent's actions (YOLO) or specific task (AUTO_EDIT).
if (
sandboxEnabled &&
(this.approvalMode === ApprovalMode.AUTO_EDIT ||
this.approvalMode === ApprovalMode.YOLO)
this.approvalMode === ApprovalMode.AUTO_EDIT ||
this.approvalMode === ApprovalMode.YOLO
) {
return false;
}
Comment on lines 293 to 298

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The removal of the sandboxEnabled check in shouldDowngradeForRedirection allows shell commands with redirections to be automatically allowed in AUTO_EDIT mode even when no sandbox is present. This enables an agent to perform arbitrary file writes on the host system by using redirections (e.g., >) with otherwise 'safe' commands. While dangerous commands are intentionally allowed in YOLO mode without a sandbox, AUTO_EDIT should still require a sandbox or user approval for such operations to maintain a secure posture.

Suggested change
if (
sandboxEnabled &&
(this.approvalMode === ApprovalMode.AUTO_EDIT ||
this.approvalMode === ApprovalMode.YOLO)
this.approvalMode === ApprovalMode.AUTO_EDIT ||
this.approvalMode === ApprovalMode.YOLO
) {
return false;
}
const sandboxEnabled = !(this.sandboxManager instanceof NoopSandboxManager);
if (
this.approvalMode === ApprovalMode.YOLO ||
(sandboxEnabled && this.approvalMode === ApprovalMode.AUTO_EDIT)
) {
return false;
}
References
  1. In YOLO mode, dangerous commands are intentionally allowed to proceed with an 'ALLOW' decision, even when no sandbox is active. This overrides the default behavior of forcing an 'ASK_USER' decision for such commands.

Expand Down
Loading