Skip to content

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 shell expansion

SeashoreShi00108b922377
diff --git a/src/capabilities/permissions.test.ts b/src/capabilities/permissions.test.ts
index d037cd44..b79c483c 100644
--- a/src/capabilities/permissions.test.ts
+++ b/src/capabilities/permissions.test.ts
@@ -145,4 +145,25 @@ describe('PermissionManager remote safety', () => {
await expect(permissions.checkShellCommand('du -sh .')).resolves.toMatchObject({ allowed: true });
expect(ask).toHaveBeenCalledTimes(4);
});
+
+ it('requires approval for safe-read commands that rely on shell expansion', 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');
+
+ // $HOME/… expands to a path the literal gate never saw (CVE-2026-28463).
+ await expect(permissions.checkShellCommand('head $HOME/secret.txt')).resolves.toMatchObject({ allowed: false });
+ // ${…} and command substitution are the same class.
+ await expect(permissions.checkShellCommand('cat ${HOME}/secret.txt')).resolves.toMatchObject({ allowed: false });
+ // $VAR discloses environment values (issue #76/#80).
+ await expect(permissions.checkShellCommand('echo $TOKEN')).resolves.toMatchObject({ allowed: false });
+ // Home shorthands expand after the check too.
+ await expect(permissions.checkShellCommand('cat ~/secret.txt')).resolves.toMatchObject({ allowed: false });
+ // A plain read relative to cwd stays auto-approved.
+ await expect(permissions.checkShellCommand('head file.txt')).resolves.toMatchObject({ allowed: true });
+ });
});
diff --git a/src/capabilities/permissions.ts b/src/capabilities/permissions.ts
index 3ebdc281..62efa908 100644
--- a/src/capabilities/permissions.ts
+++ b/src/capabilities/permissions.ts
@@ -567,6 +567,12 @@ export class PermissionManager {
// 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;
+ // Shell expansion runs after this check, so a "safe read" can still
+ // resolve outside the workspace (`head $HOME/secret`, CVE-2026-28463) or
+ // disclose environment values (`echo $TOKEN`). Require approval for any
+ // segment that relies on variable expansion or a home shorthand.
+ if (/\$[{(0-9A-Za-z_]|`/.test(segment)) return false;
+ if (/(?:^|\s)~[A-Za-z0-9_-]*(?:\/|$)/.test(segment)) return false;
const branchArgs = segment.match(/^git\s+branch(?:\s+(.*))?$/)?.[1]?.trim();
if (branchArgs && (
!branchArgs.startsWith('-')