Skip to content

fix(hosts): hand the log path to the driver as an argument, not shell syntax (#1109) - #1110

Merged
Birfy merged 2 commits into
mainfrom
fix/1109-store-quote
Nov 16, 2026
Merged

Birfy merged 2 commits into
mainfrom
fix/1109-store-quote

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Closes #1109

What changed

scripts/dsh-superagent-run.sh built each driver's command as a shell string —
tmux new-session … "$QUOTED >> '$LOG' 2>&1" and setsid sh -c "$QUOTED >> '$LOG' 2>&1".
$LOG is $STORE/worker.log, so a --store containing an apostrophe closed the
quote 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 the
    driver as arguments: LAUNCH=(bash -c 'exec >>"$1" 2>&1; shift; exec "$@"' _ "$LOG"),
    then tmux new-session -d -s "$SESSION" -c "$PWD" "${LAUNCH[@]}" "${CMD[@]}" and
    setsid "${LAUNCH[@]}" "${CMD[@]}". exec keeps the run in the same process and
    process group with the same exit status; shift drops the log path from argv, so
    neither 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 path
    tmp_path / f"it's; > {pwned}; echo '$HOME". It asserts both that the injected
    file never appears and that the child actually ran (it writes a marker), so a
    driver that silently fails to start is not green. The setsid row is forced
    through a PATH with no tmux in it instead of relying on the host lacking
    tmux; the tmux row uses the host's real tmux.
  • docs/dsh-super-agent.md — one sentence after the handoff read-back: the values
    are passed as arguments and used literally.
  • changelog.d/1109-store-quote.md — one Security fragment.

Red at base f5cc52ef, re-taken in this pass

Clean worktree at f5cc52efe41750633ac37876fc2d2894a8a6f9f3, with only
tests/test_dsh_superagent_run.py copied in:

FAILED tests/test_dsh_superagent_run.py::test_a_store_path_with_shell_metacharacters_hands_off_without_running_them[tmux]
FAILED tests/test_dsh_superagent_run.py::test_a_store_path_with_shell_metacharacters_hands_off_without_running_them[setsid]
2 failed, 5 passed in 12.19s

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 drivers
are 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 creates PWNED.

The guard measures the driver, not only my string

The tmux row runs against the host's real tmux (tmux 3.2a): 1 passed, 6 deselected. To show the row is sensitive to how a driver turns argv into a
command, I put a stand-in tmux early on PATH that joins its arguments into one
bash -c string — the behaviour the old wrapper relied on — and the same row
fails: 1 failed, 6 deselected, assert False … worker.log.is_file(). So the
version 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's command field stays the %q display text built from QUOTED.
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.json field
and 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.py without the flag → 4 passed,
    3 skipped
    (the gated group, as CI runs it)
  • python -m tools.changelog_fragments check → 47 changelog fragment(s) OK
  • python -m tools.gen_api_docs --check → docs/api.md is up to date
  • pytest -q tests/test_site_navigation.py tests/test_repo_hygiene.py →
    4 passed
  • bash -n scripts/dsh-superagent-run.sh → clean

Not run:

  • pytest -q tests/test_docs_links.py — collection needs markdown, which this
    clone's python does not have
  • mkdocs build --strict — mkdocs is not installed here; CI's build job is the line
  • the full suite — tests/test_apply_noop.py hits a read-only /home/xuke/.agentdescent
    (OSError: [Errno 30]) in this box's environment, reproduced identically in a
    clean f5cc52ef worktree, so it is environmental and not this diff

Notes

maintainer_can_modify: true is asked for in the create call. This PR's head is a
same-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 rather
than re-read as a boolean.

Size: 4 files, +85/−2 against base f5cc52ef. T2 by .github/agent/risk-rules.json
(scripts/**; the wrapper is not one of the T3 scripts). Labels mirrored from the
issue: agent-pr, bug, area:hosts; the risk:T* label is the controller's.

Written-by: AgentDescent Dev-4
Bot: AgentDescent Dev-4

Claim-Id: #1109

@HugoXK HugoXK added bug Something isn't working agent-pr Pull request opened by an agent area:hosts labels Nov 16, 2026
… 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.
@HugoXK

HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Review request at dc16eef30f1cb315001968d62deb74a00092eeb6 — the tip this PR stands at, named once, no second ask.

All nine checks green, mergeable_state: clean, no open review.

Tier, stated so it is not re-argued: T2 by .github/agent/risk-rules.json (scripts/**; the wrapper is not one of the T3 scripts) — risk tier reports the same. Closes #1109.

What to read: the driver no longer receives a shell string. LAUNCH=(bash -c 'exec >>"$1" 2>&1; shift; exec "$@"' _ "$LOG") and then tmux new-session -d -s "$SESSION" -c "$PWD" "${LAUNCH[@]}" "${CMD[@]}" / setsid "${LAUNCH[@]}" "${CMD[@]}", so neither the log path nor the command is re-parsed; the red at base f5cc52ef is both driver rows failing with the injected file created, and the parametrised test keeps the tmux row on the host's real tmux and the setsid row on a PATH without tmux.

Written-by: AgentDescent Lead

@HugoXK
HugoXK requested a review from Birfy November 16, 2026 03:46

@Birfy Birfy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 build job 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

@Birfy

Birfy commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

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 build job 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

@Birfy
Birfy merged commit 3a526ae into main Nov 16, 2026
9 of 10 checks passed
@Birfy
Birfy deleted the fix/1109-store-quote branch November 16, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-pr Pull request opened by an agent area:hosts bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(hosts): an apostrophe in --store turns the handoff wrapper's shell string into code execution

2 participants