Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(permissions): deny safe-read auto-approval for wc --files0-from
SeashoreShi6a6c6bdfef82
diff --git a/src/capabilities/permissions.test.ts b/src/capabilities/permissions.test.tsindex 72202898..38ce59c9 100644--- a/src/capabilities/permissions.test.ts+++ b/src/capabilities/permissions.test.ts@@ -103,4 +103,23 @@ describe('PermissionManager remote safety', () => {await expect(permissions.checkShellCommand('git branch new-branch')).resolves.toMatchObject({ allowed: false });expect(ask).toHaveBeenCalledTimes(6);});++ it('does not classify wc --files0-from as a safe read (indirect path deref)', async () => {+ const permissions = new PermissionManager();+ const manifest = permissions.getManifest();+ manifest.capabilities.shell.enabled = true;+ manifest.capabilities.shell.blocked = [];+ const ask = vi.fn().mockResolvedValue('no');+ permissions.onAsk(ask);+ permissions.setCurrentContext('web', 'cloud-request-1');++ // ``--files0-from`` reads the paths listed inside the file, which the+ // literal-path gate never inspects at approval time.+ await expect(permissions.checkShellCommand('wc --files0-from=list0.bin')).resolves.toMatchObject({ allowed: false });+ await expect(permissions.checkShellCommand('wc --files0-from list0.bin')).resolves.toMatchObject({ allowed: false });+ await expect(permissions.checkShellCommand('wc -l --files0-from=list0.bin')).resolves.toMatchObject({ allowed: false });+ // A plain wc read stays auto-approved.+ await expect(permissions.checkShellCommand('wc -l README.md')).resolves.toMatchObject({ allowed: true });+ expect(ask).toHaveBeenCalledTimes(3);+ });});diff --git a/src/capabilities/permissions.ts b/src/capabilities/permissions.tsindex d55eb3cb..a68b3e43 100644--- a/src/capabilities/permissions.ts+++ b/src/capabilities/permissions.ts@@ -559,6 +559,10 @@ export class PermissionManager {// Redirection turns otherwise read-only commands such as cat/echo into writes.if (/\d*(?:>{1,2}|<{1,2})|&>/.test(segment)) return false;if (/^find\b.*(?:^|\s)-(?:delete|exec|execdir|ok|okdir)\b/.test(segment)) return false;+ // ``wc --files0-from=<file>`` dereferences paths listed inside ``<file>``+ // at execution time, so the literal-path gate never sees them and the read+ // can escape the approved scopes.+ if (/^wc\b.*(?:^|\s)--files0-from\b/.test(segment)) return false;const branchArgs = segment.match(/^git\s+branch(?:\s+(.*))?$/)?.[1]?.trim();if (branchArgs && (!branchArgs.startsWith('-')