Skip to content

fix(security): name the hidden target when a shell word links to a secret - #307

Merged
Zongwei9888 merged 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/symjack-shell-path
Nov 16, 2026
Merged

Zongwei9888 merged 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/symjack-shell-path

Conversation

@raymondginger2018-sudo

@raymondginger2018-sudo raymondginger2018-sudo commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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 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_path resolves 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:

    'video.mp4' links to '/path/to/.env', a protected path; confirm before this runs
    
  • 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 deny under approval 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

command 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 https://curl.se/ca/cacert.pem ask ask
openssl req -keyout key.pem -out cert.pem ask ask
uvicorn --ssl-keyfile key.pem ask ask
grep -n id_rsa README.md ask ask
cp video.mp4 out/ (video.mp4 -> .env) ask ask, naming the target

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 staying ask, and that a non-shell tool's command argument is not scanned.

ruff 0.15.21 check and format --check clean. Rebased onto 3dcb0fb4.

Dependency note

None. One module plus its tests; no new file, no new runtime path.

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor Author

Requesting a security review for this change, @Zongwei9888.

Two steps from the repo's security-change process could not be performed from
the fork side, so I am noting them here instead of leaving them as silent gaps:

  • security label: not attempted -- the repository has no such label, and
    POST /issues/307/labels is 403 for a fork contributor (needs write access).
  • POST /pulls/307/requested_reviewers: returns 404 from the fork side.

This comment is therefore the review request itself.

Why the change is safe

The denylist contents and the DENY semantics are unchanged. The only behavioural
delta is that a shell command whose operand resolves -- after realpath -- onto
a denylisted basename is now DENY instead of allow. False-positive risk is
bounded by the existing basename-shaped denylist, and four ordinary commands
(echo, grep -rn, git log --oneline, npm run build) are pinned as
negative controls in the tests.

Bounded scope

One new stdlib import (shlex), no new files, no dependency on unmerged work.
The reviewed function is_sensitive_path itself is not modified -- it just
receives the shell-command operands it was previously never handed.

@Zongwei9888

Copy link
Copy Markdown
Contributor

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":

  • cp .env.example .env
  • source .env
  • docker compose --env-file .env up
  • echo PORT=3000 >> .env
  • git add .env.example
  • jq -r .key package.json
  • curl -O https://curl.se/ca/cacert.pem
  • openssl … -keyout key.pem
  • uvicorn --ssl-keyfile key.pem
  • grep -n id_rsa README.md

This goes against a deliberate choice on main. Keeping .env, *.pem and *.key out of bash is intentional; see the comment above _SENSITIVE_HOME_PATHS. The OS sandbox already keeps commands away from the home credential stores: in Ask mode, a cp through a link to one fails with "Operation not permitted". And builds legitimately read files with those names.

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 .env.

A shape we'd merge:

  1. Consider only words that are existing symlinks whose own name isn't sensitive but whose target is.
  2. Turn that into a confirmation that names the real target ("video.mp4 links to .env"), even when an allow rule matched, rather than a deny.
  3. Drop the references to the external write-up from comments and tests.
  4. Add a test that cp .env.example .env still asks.

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.
@raymondginger2018-sudo raymondginger2018-sudo changed the title fix(security): screen paths inside shell commands for sensitive targets fix(security): name the hidden target when a shell word links to a secret Nov 16, 2026
@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor Author

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: is_sensitive_path resolves realpath, so asking it "is this link's own name sensitive?" answers for the target instead — which filtered out the only case the helper exists to report. The own-name test is now a pattern match on the unresolved path.

2. A confirmation that names the real target, not a deny — including when an allow rule matched:

'video.mp4' links to '/path/to/.env', a protected path; confirm before this runs

It is raised on the explicit-allow branch, the full-auto branch, and the mode-default path, and it still downgrades to deny under approval policy: never. I also wired it into Ask mode: that is where the prompt is shown, so it is where the target has to be named, otherwise the reason is the generic "Running a command needs your approval."

3. Dropped the external write-up references from both the comment block and the tests.

4. Added the test you asked for. cp .env.example .env stays ask, and it sits in a table with the other nine commands you compared.

Decision table, Ask mode, main -> branch — every one of the ten is unchanged, only the link case gains a name:

command 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, naming the target

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 (tests/test_harness_permissions.py), ruff 0.15.21 check and format clean, rebased onto 3dcb0fb4.

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.

@Zongwei9888
Zongwei9888 merged commit fe4cb51 into HKUDS:main Nov 16, 2026
12 checks passed
@Zongwei9888

Copy link
Copy Markdown
Contributor

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):

  • More operand shapes are checked:
    • redirect targets: echo x >video.mp4, cat <video.mp4;
    • --opt=value, if=value and curl's @file;
    • command text inside a word: bash -c '...', "$(...)".
  • The whole path is followed, not just the last word. That covers a linked directory on the way (data/credentials with data linked to ~/.aws), .. after a link, and Windows junctions.
  • No false prompts in a linked workspace. A workspace opened through a symlink (macOS /tmp, for example) no longer prompts on prose such as "server.pem." in a commit message.
  • Parsing is robust and fast:
    • # inside a word is treated as an ordinary character;
    • commands that are very long or have unbalanced quotes are split with a linear pattern;
    • a 720 KB here-document takes 0.1 s.
  • Rules can't wave a disguised link through:
    • an earlier "always allow cp …" for the session no longer covers a command that reaches a protected file through a link; its session scope is that exact line;
    • a matching ask rule names the target too.

Asking for reads through such a link as well is fine as it is.

Zongwei9888 added a commit that referenced this pull request Nov 17, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants