sandbox native filesystem tools to prevent /proc/self/environ exfiltration (#509)
* sandbox native filesystem tools to prevent /proc/self/environ exfiltration the agent's native Read/Grep/Edit tools can bypass the shell sandbox by reading /proc/self/environ directly. this adds agent-native filesystem restrictions using the highest-precedence, non-overridable config for each CLI: OpenCode: OPENCODE_PERMISSION env var with external_directory deny-all + /tmp allow, plus deletion of untrusted .opencode/plugins/ and .opencode/tools/ before launch. Claude Code: managed-settings.json at /etc/claude-code/ with denyRead, permissions.deny, allowManagedPermissionRulesOnly, allowManagedHooksOnly. also --setting-sources user and --disallowedTools path patterns as belt-and-suspenders. Made-with: Cursor * add Glob to Claude Code /proc and /sys deny lists closes gap identified in review — Glob can enumerate /proc entries. added to both managed-settings.json permissions.deny and --disallowedTools. Made-with: Cursor * run token-exfil test with both agents, hint at native /proc reads changed tag from "agnostic" (opentoad-only) to "security" so the test runs with both opentoad and claude. updated prompt to explicitly instruct the agent to try reading /proc/self/environ via native Read tool. added API keys to action-agnostic CI job for claude support. Made-with: Cursor * move token-exfil to crossagent matrix, remove redundant permissions.deny - moved token-exfil from agnostic/ to crossagent/ so it runs via the agent matrix (claude + opentoad in parallel) instead of sequentially - removed permissions.deny per-tool rules from managed-settings.json; sandbox.filesystem.denyRead is the single enforcement mechanism - reverted action-agnostic env vars to minimal set - updated wiki to match Made-with: Cursor * document post-spawn API key deletion analysis in security wiki evaluated whether API key env vars can be deleted from agent processes after spawn. OpenCode snapshots env at startup (safe to delete), but Claude Code re-reads process.env per request (not viable). documented as further exploration item with per-agent breakdown and caveats. Made-with: Cursor * fix stale tokenExfil path references in wiki docs moved from test/agnostic/ to test/crossagent/ in directory tree and adversarial test example. Made-with: Cursor * revert accidental prisma.config.ts changes Made-with: Cursor * hardcode PULLFROG_MODEL per agent in test runner to avoid DB model mismatch when PULLFROG_AGENT forces a specific agent, the DB-configured model may belong to a different provider (e.g. openai model with claude agent). PULLFROG_MODEL short-circuits the DB slug resolution entirely. Made-with: Cursor
This commit is contained in:
committed by
pullfrog[bot]
parent
36cc5cde14
commit
8cd36d221a
@@ -148985,6 +148985,7 @@ Use mini or auto effort.`
|
||||
var modes = computeModes();
|
||||
|
||||
// agents/claude.ts
|
||||
import { execFileSync as execFileSync2 } from "node:child_process";
|
||||
import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
||||
import { join as join10 } from "node:path";
|
||||
import { performance as performance6 } from "node:perf_hooks";
|
||||
@@ -149441,6 +149442,43 @@ ${stderrContext}`
|
||||
};
|
||||
}
|
||||
}
|
||||
var MANAGED_SETTINGS_DIR = "/etc/claude-code";
|
||||
var MANAGED_SETTINGS_PATH = `${MANAGED_SETTINGS_DIR}/managed-settings.json`;
|
||||
var managedSettings = {
|
||||
allowManagedPermissionRulesOnly: true,
|
||||
allowManagedHooksOnly: true,
|
||||
permissions: {
|
||||
deny: [
|
||||
"Read(//proc/**)",
|
||||
"Read(//sys/**)",
|
||||
"Grep(//proc/**)",
|
||||
"Grep(//sys/**)",
|
||||
"Edit(//proc/**)",
|
||||
"Edit(//sys/**)",
|
||||
"Glob(//proc/**)",
|
||||
"Glob(//sys/**)"
|
||||
]
|
||||
},
|
||||
sandbox: {
|
||||
filesystem: {
|
||||
denyRead: ["/proc", "/sys"]
|
||||
}
|
||||
}
|
||||
};
|
||||
function installManagedSettings() {
|
||||
if (process.env.CI !== "true") return;
|
||||
const content = JSON.stringify(managedSettings, null, 2);
|
||||
try {
|
||||
execFileSync2("sudo", ["mkdir", "-p", MANAGED_SETTINGS_DIR]);
|
||||
execFileSync2("sudo", ["tee", MANAGED_SETTINGS_PATH], {
|
||||
input: content,
|
||||
stdio: ["pipe", "ignore", "pipe"]
|
||||
});
|
||||
log.debug(`\xBB wrote managed settings to ${MANAGED_SETTINGS_PATH}`);
|
||||
} catch (err) {
|
||||
log.warning(`\xBB failed to install managed settings: ${err}`);
|
||||
}
|
||||
}
|
||||
var claude = agent({
|
||||
name: "claude",
|
||||
install: installClaudeCli,
|
||||
@@ -149462,6 +149500,7 @@ var claude = agent({
|
||||
});
|
||||
const mcpConfigPath = writeMcpConfig(ctx);
|
||||
const effort = resolveEffort(model);
|
||||
installManagedSettings();
|
||||
const args2 = [
|
||||
cliPath,
|
||||
"-p",
|
||||
@@ -149501,8 +149540,8 @@ var claude = agent({
|
||||
});
|
||||
|
||||
// agents/opentoad.ts
|
||||
import { execFileSync as execFileSync2 } from "node:child_process";
|
||||
import { mkdirSync as mkdirSync4 } from "node:fs";
|
||||
import { execFileSync as execFileSync3 } from "node:child_process";
|
||||
import { mkdirSync as mkdirSync4, rmSync } from "node:fs";
|
||||
import { join as join11 } from "node:path";
|
||||
import { performance as performance7 } from "node:perf_hooks";
|
||||
async function installOpencodeCli() {
|
||||
@@ -149538,7 +149577,7 @@ function buildSecurityConfig(ctx, model) {
|
||||
}
|
||||
function getOpenCodeModels(cliPath) {
|
||||
try {
|
||||
const output = execFileSync2(cliPath, ["models"], {
|
||||
const output = execFileSync3(cliPath, ["models"], {
|
||||
encoding: "utf-8",
|
||||
timeout: 3e4,
|
||||
env: process.env
|
||||
@@ -149886,11 +149925,17 @@ var opentoad = agent({
|
||||
env: homeEnv,
|
||||
agent: "opencode"
|
||||
});
|
||||
rmSync(join11(process.cwd(), ".opencode", "plugins"), { recursive: true, force: true });
|
||||
rmSync(join11(process.cwd(), ".opencode", "tools"), { recursive: true, force: true });
|
||||
const args2 = ["run", ctx.instructions.full, "--format", "json", "--print-logs"];
|
||||
const permissionOverride = JSON.stringify({
|
||||
external_directory: { "*": "deny", "/tmp/*": "allow" }
|
||||
});
|
||||
const env2 = {
|
||||
...process.env,
|
||||
...homeEnv,
|
||||
OPENCODE_CONFIG_CONTENT: buildSecurityConfig(ctx, model),
|
||||
OPENCODE_PERMISSION: permissionOverride,
|
||||
GOOGLE_GENERATIVE_AI_API_KEY: process.env.GOOGLE_GENERATIVE_AI_API_KEY || process.env.GEMINI_API_KEY
|
||||
};
|
||||
const repoDir = process.cwd();
|
||||
|
||||
Reference in New Issue
Block a user