Skip to content
Closed
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
17 changes: 17 additions & 0 deletions src/lib/agent/runner/harness/pi/__tests__/security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,23 @@ describe('pi-security: plain rm matches the anthropic arm', () => {
);
});

test('an allowed scoped rm never captures a `bash denied` event', async () => {
// wizardCanUseTool records analytics on every deny, so the rescue must be
// decided BEFORE consulting it — otherwise each allowed rm still shows up
// in telemetry as denied.
const { analytics } = await import('@utils/analytics');
const capture = vi.spyOn(analytics, 'wizardCapture');
try {
expect(await rmBlocked('rm .posthog-events.json')).toBe(false);
expect(capture).not.toHaveBeenCalledWith(
'bash denied',
expect.anything(),
);
} finally {
capture.mockRestore();
}
});

test('normalizes a relative workingDirectory', async () => {
const relRoot = path.relative(process.cwd(), path.resolve('/project'));
expect(
Expand Down
18 changes: 11 additions & 7 deletions src/lib/agent/runner/harness/pi/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,24 @@ export async function evaluateToolCall(
llmProvider?: LLMProvider,
): Promise<GateDecision> {
try {
const policy = toClaudePolicyCall(toolName, input);
const decision = wizardCanUseTool(policy.name, policy.input, {
disallowedTools: ctx.disallowedTools,
wizardAskPending: ctx.getWizardAskPending?.() ?? false,
});
// The allowlist is a pi-only restriction; the anthropic arm runs bash
// unrestricted and leans on the shared YARA scan. Let a plain `rm` of
// project files through to that same scan so pi matches that behavior.
// Checked BEFORE wizardCanUseTool: its deny path captures a `bash denied`
// analytics event, which would record every allowed scoped rm as denied.
const allowedLikeAnthropic =
toolName === 'bash' &&
isScopedFileRemoval(str(input.command), ctx.workingDirectory);

if (decision.behavior === 'deny' && !allowedLikeAnthropic) {
return { block: true, reason: decision.message };
if (!allowedLikeAnthropic) {
const policy = toClaudePolicyCall(toolName, input);
const decision = wizardCanUseTool(policy.name, policy.input, {
disallowedTools: ctx.disallowedTools,
wizardAskPending: ctx.getWizardAskPending?.() ?? false,
});
if (decision.behavior === 'deny') {
return { block: true, reason: decision.message };
}
}

const yaraReason = await preExecutionYaraBlock(
Expand Down
Loading