#12958: fix: block agent read access to sensitive config and credential files
agents
stale
Cluster:
Security Enhancements and Fixes
Prevent the read tool from accessing OpenClaw config files (openclaw.json and legacy variants) and the credentials directory. This Stops indirect prompt injection attacks where a malicious web page tricks the model into reading ~/.openclaw/openclaw.json and exfiltrating the gateway auth token.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change adds a sensitive-path guard to the read tool to prevent the agent from reading OpenClaw config files (e.g. `openclaw.json` and legacy variants) and anything under the state `credentials/` directory, using `resolveStateDir()` as the root.
The guard is implemented in `src/agents/pi-tools.read.ts` by introducing `isSensitiveOpenClawPath()`/`assertNotSensitivePath()` and calling it from both `createOpenClawReadTool()` and an additional wrapper inside `createSandboxedReadTool()`, before delegating to the underlying `pi-coding-agent` read tool (with existing MIME normalization/sanitization preserved).
<h3>Confidence Score: 2/5</h3>
- This PR reduces risk but still has clear bypasses for the new sensitive-file guard.
- The intent is correct, but the sensitive-path check can be bypassed via parameter aliasing (`file_path`) and via Unicode-space normalization differences between the sandbox resolver and the new `expandTilde()` logic. These are directly relevant to the PR’s security goal (blocking credential/config reads).
- src/agents/pi-tools.read.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#16929: fix(security): block access to sensitive directories from within sa...
by CornBrother0x · 2026-02-15
80.1%
#10514: Security: harden AGENTS.md with gateway, prompt injection, and supp...
by catpilothq · 2026-02-06
77.6%
#7983: feat(security): add secure coding guidelines to system prompt
by TGambit65 · 2026-02-03
76.2%
#12231: fix(read): add directory check before reading file
by higginsvott · 2026-02-09
76.2%
#6257: Fix: Create sensitive directories with mode 0o700
by sloppy-claw · 2026-02-01
75.8%
#15756: [Security]: strip provider apiKey from models.json before prompt se...
by SecBear · 2026-02-13
75.6%
#15941: fix(sessions): allow session file paths from other agents' sessions...
by LiJianLi128 · 2026-02-14
75.4%
#7085: test: skip flaky workspace-paths & safe-bins tests on non-Linux/CI ...
by ThinkIbrokeIt · 2026-02-02
75.2%
#15757: feat(security): add hardening gap audit checks
by saurabhsh5 · 2026-02-13
75.1%
#11439: fix(security): warn on relative OPENCLAW_CONFIG_PATH and disable co...
by coygeek · 2026-02-07
75.0%