Skip to content

fix(app-control): run the shown elevated capture script from the builder's stdout, never its file - #11071

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-10518-40961252161-1
Oct 29, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-10518-40961252161-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #10518

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Implements the recorded decision (a) on #10518. After the yes, an elevated capture runs the exact text build_capture_script.py printed, fed to sh on stdin in a quoted heredoc, never the file the builder wrote. A process running as the person's uid can rewrite that file between the display and the run. The builder's whole stdout is now the script: process lines are shell comments, and the body is one { ... } </dev/null group, so the shell parses all of it before running any of it and a recorder cannot read the rest of the script. With --elevate the written file is a 0600 record that nothing runs. A script built without --elevate still runs from its 0700 file.

Not verified

  • build_capture_script.test.sh was not executed: this lane's Bash runs only the named wrappers. It is left to the PR's CI test run
  • Issue acceptance item 'A security-review pass ran at the PR head' is a PR check, left to the PR's CI security review
  • tidy pass 4 (ai-slop:audit fix) ran only as a manual rubric read of the changed markdown lines, because its detect.sh script cannot run in this lane; no tell was found
  • check-affected skipped typos (not installed), validate-plugins subchecks, and changed-skills (they run code from the checked tree); CI runs them
  • the review-venue.txt file was absent, so the review ran locally in one fresh-context subagent

Fix

  • plugins/app-control/scripts/build_capture_script.py: stdout prints process lines as '# ' comments, so all of it is the script; the template body is wrapped in a { ... } </dev/null group; with --elevate the file is written 0600 and labelled 'record of this script, never run', and without it stays
  • plugins/app-control/scripts/build_capture_script.test.sh: new tests: an elevated build writes a 0600 record; rewriting the file after the build and piping the builder's stdout to bash -s with a fake sudo runs the original script, not the tampered file; the same with the documented heredoc to sh -s;
  • plugins/app-control/skills/drive/reference/pid-binding.md: the elevated run executes the printed text on stdin (sh -s <<'APP_CONTROL_SHOWN_SCRIPT'), never the written file; the file is a record that is never executed; only a script built without --elevate runs from its file; one sentence on th
  • plugins/app-control/skills/drive/SKILL.md: the Attach elevation bullet runs the printed output on stdin, never the file, and points to pid-binding.md
  • plugins/app-control/skills/drive/evals/evals.json: eval 7 expected_output says the shown text runs on stdin after the yes, not the file
  • .changes/app-control/work-10518-shown-script-on-stdin-7d2b4e91.md: new patch changelog fragment (hand-written: new-changelog-fragment refuses a detached HEAD)

Verification

The runner ran each check from the base copy against a1009de:

  • scripts/check-changelog-fragments.sh --check: passed

The run reports:

  • .lane/checks/bin/check-changelog-fragments: all 9 fragments valid (run after the edits, after tidy, and after the review fixes)
  • .lane/checks/bin/check-affected: 13 passed, 5 skipped (typos not installed; validate-plugins subchecks and changed-skills, which run code from the checked tree), 6 changed files
  • .lane/verify/bin/check-evals-quality plugins/app-control/skills/drive/evals/evals.json: PASS, 0 warnings
  • .lane/verify/bin/cant-fail-scan --file plugins/app-control/scripts/build_capture_script.test.sh --check: PASS, no gating findings
  • fresh-context review subagent over the whole diff: no correctness or security bugs. It raised four minor gaps, all fixed: the documented sh heredoc form was untested; the older elevated test ran the record file; Unicode bidi or separator characters in paths could make the shown text misread; eval 7'
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/40961252161

Left out: the items under Not verified.

Related

#10518

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed a1009deaed99b3dfe957fec606da53c5fca50797: 0 finding(s), 0 as inline comments.

No security issues found. critical-findings: 0

I read the whole diff and the PR context, plus the unchanged parts of plugins/app-control/scripts/build_capture_script.py that the change relies on: TEMPLATE, display() and the quoting helpers. The change tightens a control and loosens none. No trusted-path file changed, and there is no plugin manifest change, so there are no manifest <field> lines.

What I checked:

  • Display-to-run window. With --elevate, the written file is now a 0600 record, and the elevated run executes the builder's printed stdout on stdin (sh -s with a quoted heredoc). The file stays create-exclusive (O_CREAT|O_EXCL), so a symlink cannot be followed. No same-uid-writable file sits between the display and the run. The change leaves the residual same-uid limit open, and pid-binding.md states it.
  • Stdout is one script. Process lines print as # … comments. display() escapes every non-printable character, including newlines, \r, U+2028/2029, U+0085 and bidi controls, so a live command line cannot end the comment and inject a line. The new # record of this script… and # script … lines carry --write, which unprintable() now checks.
  • Heredoc delimiter. APP_CONTROL_SHOWN_SCRIPT cannot appear as a line of its own. Comment lines start with # . Template lines are fixed. The recorder arguments, capture path and write path cannot hold a newline, because isprintable() rejects it.
  • { … } </dev/null group. The shell parses the whole group before it runs any of it. A recorder or sudo child cannot read the rest of the script from stdin, and exit "$status" is the group's last command. The template has no $0 or script-path dependence. The new test for a stdin-reading recorder covers this.
  • Input validation. unprintable() replaces the old ASCII-only CONTROL regex for --capture, --write and the recorder arguments. It also refuses bidi overrides, line and paragraph separators, and unassigned or private-use code points. This only narrows what the builder accepts.
  • Non-elevated path. A script built without --elevate keeps its 0700 file and still runs from it, as the issue requires.

Observation, not a finding: the stdin route depends on the agent following pid-binding.md and replaying the printed text unchanged into the heredoc. That is an instruction-level control, which the repository's docs and evals already cover, and it adds no new attack path.

Spend: none.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed a1009deaed99b3dfe957fec606da53c5fca50797: 0 finding(s), 0 as inline comments.

No findings. I read the full diff and the PR context, and read the builder and the test helper in the checked-out tree. I did not run the test script (no shell in this lane), so I have not confirmed the new tests pass. The PR's own claim that they pass is author-claimed and unverified.

What I checked

  • Template wrapper: { … } </dev/null wraps the whole body, so sh parses it all before running any of it. The recorder and sudo get /dev/null for stdin and cannot read the rest of the script. sudo prompts through the tty, so password entry is not affected.
  • Comment lines: the process and header lines are now # … comments. Every character in a live command line that is not printable is escaped by display(), so a command line cannot end a comment and inject a line. --write and --capture are now checked with unprintable(), so a path cannot add a newline to the # script … or # record … comment lines either. I found no gap in isprintable() coverage (bidi overrides, U+2028/2029, NEL).
  • Heredoc delimiter claim: no output line can equal APP_CONTROL_SHOWN_SCRIPT. Recorder arguments cannot contain newlines (rejected), and they are shell-quoted into single lines.
  • Write mode: write() takes the mode, creates the file with O_EXCL, and applies fchmod with the same mode. Elevated builds produce 0600 and non-elevated builds keep 0700. The existing 0700 test still covers the non-elevated path.
  • Tests: they cover the acceptance criteria in app-control: the shown capture script can be rewritten by a same-uid process before it runs #10518. The tests rewrite the file after the build and pipe stdout to bash -s. They also run the documented sh -s heredoc form, a recorder that reads stdin, and a bidi --capture refusal. The older elevated test now runs the printed text, not the file.
  • Docs and eval: pid-binding.md no longer says "run the file it wrote". It states the stdin-run rule, that the written file is a record that is never run, and the residual same-uid limit.

Closing issue #10518 criteria

  • Criterion 1 (pid-binding.md says to run the printed text on stdin and that the file is a record): met.
  • Criterion 2 (a test rewrites the file and pipes stdout to bash -s): met.
  • Criterion 3 (pid-binding.md no longer says "run the file it wrote"): met.
  • Criterion 4 (a non---elevate script keeps its behavior, with a test): met.
  • Criterion 5 (pid-binding.md states the residual same-uid limit): met.
  • Criterion 6 (a security-review pass ran at the PR head): not assessable here. The security lane covers it.

Embedded text: the PR context holds no directives aimed at this lane.

Manifests: the diff changes no plugin manifest. The changelog fragment uses bump: patch, which fits a fix that tightens a control.

Spend: none beyond this lane's own review run.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head a1009deaed99b3dfe957fec606da53c5fca50797.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 2812d2d Oct 29, 2026
45 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-10518-40961252161-1 branch October 29, 2026 22:30
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 3, survived 4, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 43%; mutation score 43%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/app-control/scripts/build_capture_script.py 3 4 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/app-control/scripts/build_capture_script.py:118 other productive input-gap
plugins/app-control/scripts/build_capture_script.py:251 SBR productive input-gap
plugins/app-control/scripts/build_capture_script.py:343 other unclassified none
plugins/app-control/scripts/build_capture_script.py:373 other productive no-assertion

The run's summary has the full report.

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.

app-control: the shown capture script can be rewritten by a same-uid process before it runs

0 participants