Repository navigation
fix(security): name the hidden target when a shell word links to a secret - #307
Conversation
|
Requesting a security review for this change, @Zongwei9888. Two steps from the repo's security-change process could not be performed from
This comment is therefore the review request itself. Why the change is safeThe denylist contents and the DENY semantics are unchanged. The only behavioural Bounded scopeOne new stdlib import ( |
|
Thanks for this, and for the review request. A link whose name hides its target on the approval prompt is a fair point, and your symlink test shows it. We can't merge it as written, though. Ordinary commands become impossible to approve. Every word of the command now goes through the credential check, and that check is a deny no rule can override. We compared decisions on main and on this branch. In Ask mode, all of these went from "ask" to "deny":
This goes against a deliberate choice on main. Keeping Only Ask mode is affected. Full access turns the check off and Read only already denies bash. So the real gain is a link to a secret inside the workspace, such as A shape we'd merge:
Happy to review again once updated. |
…cret
A shell command's operands sit inside the command string, under a key no path
rule names, so a word like `video.mp4` never reached the sensitive-path check.
When that word was a symlink to `.env`, the approval prompt showed the harmless
end and the write landed on the secret.
The first attempt screened every word against the denylist, which turned ten
ordinary commands (`cp .env.example .env`, `source .env`, `git add
.env.example`, ...) from "ask" into denials no rule could override. That
conflicts with a deliberate choice on main and only ever affected Ask mode.
This narrows the probe to the shape that actually deceives the prompt: an
existing symlink whose own name is not protected, whose resolved target is.
Both conditions matter -- `is_sensitive_path` resolves links, so asking it
whether the alias's own name is sensitive would answer for the target instead.
The result is a confirmation that names both ends, not a deny:
'video.mp4' links to '/path/to/.env', a protected path; confirm before this runs
It is raised wherever the call would otherwise be allowed, so an allow rule
cannot quietly wave it through: the explicit-allow branch, the full-auto branch,
and the mode-default path all upgrade to ask (and still downgrade to deny under
an "approval policy: never").
Decision table, same commands, both trees, Ask mode (main -> branch):
cp .env.example .env ask -> ask
source .env ask -> ask
docker compose --env-file .env up ask -> ask
echo PORT=3000 >> .env ask -> ask
git add .env.example ask -> ask
jq -r .key package.json ask -> ask
curl -O .../cacert.pem ask -> ask
openssl -keyout key.pem ask -> ask
uvicorn --ssl-keyfile key.pem ask -> ask
grep -n id_rsa README.md ask -> ask
cp video.mp4 out/ (-> .env) ask -> ask, now naming the target
Tests: tests/test_harness_permissions.py, 47 passed. They pin the alias shape,
the named confirmation in both full-auto and ask mode, the allow-rule case, the
ten commands above staying ask, and that a non-shell tool's `command` argument
is not scanned. ruff 0.15.21 check and format clean.
5d6ce01 to
fe4cb51
Compare
|
Thanks — you were right on all four points, and the reproduction was exact. 1. Narrowed to existing symlinks whose own name is not protected but whose target is. One detail worth flagging because it bit me: 2. A confirmation that names the real target, not a deny — including when an allow rule matched: It is raised on the explicit-allow branch, the full-auto branch, and the mode-default path, and it still downgrades to 3. Dropped the external write-up references from both the comment block and the tests. 4. Added the test you asked for. Decision table, Ask mode, main -> branch — every one of the ten is unchanged, only the link case gains a name:
Plain words are no longer screened at all — only their link targets are — so the deliberate "those names stay out of bash" choice and the sandbox are left as they were. 47 tests pass ( One thing I deliberately left alone, in case you want it: reads through such a link are confirmed too, not just writes. Distinguishing them would mean classifying each subcommand, which felt like the wrong place to start — say the word if you would rather have it. |
|
Merged in 8ce9389. Thank you for narrowing this down so carefully; the decision table made the review easy. We added follow-ups on top (d6f83a8, 05e48e7, 18215a6, 55c3c78):
Asking for reads through such a link as well is fine as it is. |
Add the news entry and changelog for the 2026-11-16 community batch (#289, #293, #303, #307) and fold the 2026-10-31 entry into the earlier updates. The three points under "What Deep means" now match the numbered parts of the framework figure, self-evolution is named as planned, and "Why DeepCode" no longer repeats them.
Summary
A shell command's operands sit inside the command string, under a key no path rule names, so a word like
video.mp4never reached the sensitive-path check. When that word was a symlink to.env, the approval prompt showed the harmless end and the write landed on the secret.The first attempt screened every word against the denylist, which turned ten ordinary commands into denials no rule could override. This narrows the probe to the shape that actually deceives the prompt, and turns it into a confirmation instead of a deny.
What changed
Only existing symlinks whose own name is not protected, and whose resolved target is. Both halves matter:
is_sensitive_pathresolves links, so asking it whether the alias's own name is sensitive would answer for the target instead — the one case the helper exists to report. The own-name test is a pattern match on the unresolved path.A confirmation naming both ends, not a deny:
Raised wherever the call would otherwise be allowed, so an allow rule cannot quietly wave it through: the explicit-allow branch, the full-auto branch, and the mode-default path. It still downgrades to
denyunderapproval policy: never, like every other ask.Ask mode included. That is where the prompt is shown, so that is where the target has to be named; otherwise the fallback reason is the generic "Running a command needs your approval."
No external write-up references remain in the comments or the tests.
Decision table — same commands, both trees, Ask mode
cp .env.example .envsource .envdocker compose --env-file .env upecho PORT=3000 >> .envgit add .env.examplejq -r .key package.jsoncurl -O https://curl.se/ca/cacert.pemopenssl req -keyout key.pem -out cert.pemuvicorn --ssl-keyfile key.pemgrep -n id_rsa README.mdcp video.mp4 out/(video.mp4 -> .env)Tests
tests/test_harness_permissions.py— 47 passed. New cases pin the alias shape, the named confirmation in full-auto and ask mode, the allow-rule case, the ten commands above stayingask, and that a non-shell tool'scommandargument is not scanned.ruff 0.15.21 checkandformat --checkclean. Rebased onto3dcb0fb4.Dependency note
None. One module plus its tests; no new file, no new runtime path.