Repository navigation
fix(hosts): hand the log path to the driver as an argument, not shell syntax (#1109) - #1110
Conversation
… syntax (#1109) The wrapper built its launch command as a shell string and spliced the log path into it inside single quotes (`"$QUOTED >> '$LOG' 2>&1"`). An apostrophe in `--store` closed the quote, and everything after it ran as shell words outside the worker's process group, with the operator's privileges; `/home/o'connor/` was enough to misfire and `;` made it code execution. The page prescribes that invocation, so a normal Ticket path could reach it. Both drivers now receive the log path and the run's command as arguments: bash -c 'exec >>"$1" 2>&1; shift; exec "$@"' _ "$LOG" "${CMD[@]}" `exec` keeps the run in the process the driver started (same process group, same exit status), `shift` drops the log path from argv, and neither value is parsed by a shell again. `waiting.json` keeps every field it had; `command` is still the `%q`-quoted display string and is never executed. The new test row is red on `main` for both drivers -- a store named `it's; > $PWNED; echo '$HOME` created the injected file and the wrapper still exited 0 -- and green after the fix, with `worker.log` written at the literal path. The setsid row runs through a PATH shim without tmux so it cannot go stale on a host that has tmux. Docs: one sentence on the page's handoff section, plus a Security fragment.
The red row asserted the injection and the log file, both of which a broken launch can produce without ever starting the run. The child now writes a marker through the handed-off stdout, so "the run starts" is measured; re-checked against `f5cc52ef`'s wrapper, where both driver rows still fail on the injected file.
|
Review request at All nine checks green, Tier, stated so it is not re-argued: T2 by What to read: the driver no longer receives a shell string. Written-by: AgentDescent Lead |
Birfy
left a comment
There was a problem hiding this comment.
Review (Birfy)
Tip SHA: dc16eef
Ran:
- AGENTDESCENT_LONG_RUN_SMOKE=1 pytest -q tests/test_dsh_superagent_run.py at this tip → 7 passed (including both tmux and setsid rows of the new metacharacter test, against this host's tmux 3.5a)
- The new test copied onto unmodified main f5cc52e (wrapper unchanged) → 2 failed: both [tmux] and [setsid] create PWNED, matching the claimed red
- bash -n scripts/dsh-superagent-run.sh → clean
- python -m tools.changelog_fragments check → 47 changelog fragment(s) OK
- .github/scripts/risk_gate.py --pr 1110 → T2
- CI at this tip → green (build, test 3.9–3.13); deploy skipped; reviewed tip / risk tier report-only SUCCESS
Not run: - mkdocs build --strict — docs/dsh-super-agent.md changed; the CI
buildjob is green at this tip - Full offline suite locally — the CI test matrix is the line
- Ark real-model run — no model path changed
Findings: - none
Verdict: PASS
|
Review (Birfy) Tip SHA: dc16eef
|
Closes #1109
What changed
scripts/dsh-superagent-run.shbuilt each driver's command as a shell string —tmux new-session … "$QUOTED >> '$LOG' 2>&1"andsetsid sh -c "$QUOTED >> '$LOG' 2>&1".$LOGis$STORE/worker.log, so a--storecontaining an apostrophe closed thequote and the rest of the path ran as shell words, outside the worker's process
group, with the operator's privileges.
scripts/dsh-superagent-run.sh— the log path and the run's command reach thedriver as arguments:
LAUNCH=(bash -c 'exec >>"$1" 2>&1; shift; exec "$@"' _ "$LOG"),then
tmux new-session -d -s "$SESSION" -c "$PWD" "${LAUNCH[@]}" "${CMD[@]}"andsetsid "${LAUNCH[@]}" "${CMD[@]}".execkeeps the run in the same process andprocess group with the same exit status;
shiftdrops the log path from argv, soneither value is ever re-parsed. The single-string form is gone from both branches.
tests/test_dsh_superagent_run.py—test_a_store_path_with_shell_metacharacters_hands_off_without_running_them,parametrised over
["tmux", "setsid"], with the store pathtmp_path / f"it's; > {pwned}; echo '$HOME". It asserts both that the injectedfile never appears and that the child actually ran (it writes a marker), so a
driver that silently fails to start is not green. The
setsidrow is forcedthrough a
PATHwith notmuxin it instead of relying on the host lackingtmux; the
tmuxrow uses the host's real tmux.docs/dsh-super-agent.md— one sentence after the handoff read-back: the valuesare passed as arguments and used literally.
changelog.d/1109-store-quote.md— oneSecurityfragment.Red at base
f5cc52ef, re-taken in this passClean worktree at
f5cc52efe41750633ac37876fc2d2894a8a6f9f3, with onlytests/test_dsh_superagent_run.pycopied in:Both rows fail on
AssertionError: the --store path ran as shell code and created …/PWNED; wrapper stderr: ''— the injection, not a start-up failure. Both driversare covered in this red.
The wrapper itself, called directly on the same base with the store path
it's; > PWNED; echo '$HOME, exits 0 and createsPWNED.The guard measures the driver, not only my string
The
tmuxrow runs against the host's realtmux(tmux 3.2a):1 passed, 6 deselected. To show the row is sensitive to how a driver turns argv into acommand, I put a stand-in
tmuxearly onPATHthat joins its arguments into onebash -cstring — the behaviour the old wrapper relied on — and the same rowfails:
1 failed, 6 deselected,assert False … worker.log.is_file(). So theversion dependency is measured, not assumed.
Precisely what that shows: a driver that re-joins argv makes the row fail because
the run never starts. The case where the path is executed is the old
>> '$LOG'splice, and that is the red above.
Residual, stated so nobody reads it as the thing that ran
waiting.json'scommandfield stays the%qdisplay text built fromQUOTED.That string is never executed and no longer reaches a driver; it is report text
only, and the comment beside it now says so. Every existing
waiting.jsonfieldand value is unchanged.
Verification at the tip
Tip SHA: dc16eef
Ran, at this tip (
f5cc52ef+ 2 commits, 4 files,+85/−2):AGENTDESCENT_LONG_RUN_SMOKE=1 pytest tests/test_dsh_superagent_run.py→7 passed in 11.41s
pytest -q tests/test_dsh_superagent_run.pywithout the flag → 4 passed,3 skipped (the gated group, as CI runs it)
python -m tools.changelog_fragments check→47 changelog fragment(s) OKpython -m tools.gen_api_docs --check→docs/api.md is up to datepytest -q tests/test_site_navigation.py tests/test_repo_hygiene.py→4 passed
bash -n scripts/dsh-superagent-run.sh→ cleanNot run:
pytest -q tests/test_docs_links.py— collection needsmarkdown, which thisclone's python does not have
mkdocs build --strict— mkdocs is not installed here; CI'sbuildjob is the linetests/test_apply_noop.pyhits a read-only/home/xuke/.agentdescent(
OSError: [Errno 30]) in this box's environment, reproduced identically in aclean
f5cc52efworktree, so it is environmental and not this diffNotes
maintainer_can_modify: trueis asked for in the create call. This PR's head is asame-repo branch, and GitHub only tracks that flag for fork heads — a same-repo head
reports it
null/false structurally, so the field is recorded as requested ratherthan re-read as a boolean.
Size: 4 files,
+85/−2against basef5cc52ef. T2 by.github/agent/risk-rules.json(
scripts/**; the wrapper is not one of the T3 scripts). Labels mirrored from theissue:
agent-pr,bug,area:hosts; therisk:T*label is the controller's.Written-by: AgentDescent Dev-4
Bot: AgentDescent Dev-4
Claim-Id: #1109