Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(permissions): close the residual safe-read bypass family around find
Salman Qureshif465e6fb9e8c
diff --git a/src/capabilities/permissions.test.ts b/src/capabilities/permissions.test.tsindex 38ce59c9..d037cd44 100644--- a/src/capabilities/permissions.test.ts+++ b/src/capabilities/permissions.test.ts@@ -122,4 +122,27 @@ describe('PermissionManager remote safety', () => {await expect(permissions.checkShellCommand('wc -l README.md')).resolves.toMatchObject({ allowed: true });expect(ask).toHaveBeenCalledTimes(3);});++ it('find -fprint/-fprintf/-files0-from are side-effectful or indirect — require approval', 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');++ // -fprint/-fprintf WRITE files with an attacker-chosen path — the same+ // arbitrary-write class the -exec deny covers (issue #110's family).+ await expect(permissions.checkShellCommand('find . -fprint out.txt')).resolves.toMatchObject({ allowed: false });+ await expect(permissions.checkShellCommand('find . -fprintf out.txt %p')).resolves.toMatchObject({ allowed: false });+ // -files0-from dereferences a path list the literal-path gate never sees.+ await expect(permissions.checkShellCommand('find . -files0-from=list.bin')).resolves.toMatchObject({ allowed: false });+ // The generic indirection rule covers the other safe-read commands.+ await expect(permissions.checkShellCommand('du --files0-from=list.bin')).resolves.toMatchObject({ allowed: false });+ // Plain reads must keep working without a prompt.+ await expect(permissions.checkShellCommand('find . -maxdepth 1')).resolves.toMatchObject({ allowed: true });+ await expect(permissions.checkShellCommand('du -sh .')).resolves.toMatchObject({ allowed: true });+ expect(ask).toHaveBeenCalledTimes(4);+ });});diff --git a/src/capabilities/permissions.ts b/src/capabilities/permissions.tsindex a68b3e43..3ebdc281 100644--- a/src/capabilities/permissions.ts+++ b/src/capabilities/permissions.ts@@ -558,11 +558,15 @@ export class PermissionManager {private isSafeReadSegment(segment: string): boolean {// 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;+ // find's action flags are side-effectful: -exec/-execdir/-ok/-okdir run+ // arbitrary commands, -fprint/-fprintf write files, and -files0-from+ // dereferences a path list at execution time (the literal-path gate never+ // sees those paths).+ if (/^find\b.*(?:^|\s)-(?:delete|exec|execdir|ok|okdir|fprintf|fprint|files0-from)\b/.test(segment)) return false;+ // File-list indirection in any safe-read command (wc/du/sort/…): the+ // paths live inside the referenced file, invisible to the literal-path+ // gate, so the read can escape the approved scopes.+ if (/(?:^|\s)--files0-from(?:=|\s|$)/.test(segment)) return false;const branchArgs = segment.match(/^git\s+branch(?:\s+(.*))?$/)?.[1]?.trim();if (branchArgs && (!branchArgs.startsWith('-')