Skip to content

Scope the test agent's tools and stop trusting the app's output - #32

Merged
pierridotite merged 1 commit into
pierridotite:mainfrom
amirkhakshour:security/scoped-agent-tools-and-artifact-guards
Nov 27, 2026
Merged

pierridotite merged 1 commit into
pierridotite:mainfrom
amirkhakshour:security/scoped-agent-tools-and-artifact-guards

Conversation

@amirkhakshour

@amirkhakshour amirkhakshour commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes six of the seven high-severity findings in #31 by mini-ork run: https://console.miniork.dev/r/9XxOuNS1DWUYaEk8zoxM7w. The seventh (BUILD_ARGS is in the environment of the step that runs the app's own build code) is a design decision and is left alone — say which way you want it and I will follow up.

The short version: everything here treats the app under test as untrusted, because that is what it is.

scripts/android/run_agent.sh, scripts/ios/run_agent.sh — the agent's tool grant is now the files the briefs name, not the workspace. Read and Bash(cat:*) reached .git/config (the persona jobs persist the GitHub token there) and /proc/self/environ (the model key), and bare Write could replace scripts/encrypt_results.sh, which the workflow runs afterwards as the runner. Writes stay in results/. This matches what the web agent already does (scripts/web/run_agent.sh).

scripts/android/run_agent.sh — the package name read from the APK is checked against [A-Za-z0-9._-]+ before it reaches adb shell. adb shell joins its arguments into one string the device shell parses, so a package named x; id was a command. scripts/device_state.py:24 already has this guard; this is the same rule in the same place it is needed.

scripts/collect.sh — the archive is listed before it is extracted; a member with .. or an absolute path, or a symlink member, aborts the run with a clear message. The archive is built on runners where the app's build code and the agent can both write into results/, so the collector should not assume it is sane.

.github/workflows/agent-testers.yml — three changes:

  • framework goes through env: like every other input instead of being interpolated into run:. Dispatch rights plus no secret read was previously enough for arbitrary shell in a step that holds BUILD_ARGS and ARTIFACT_PASSPHRASE.
  • the Check setup step fails when results_public.pem is still the template's key. This is the one change that can turn a previously-passing run red: a fork that has never run ./setup.sh will now get a clear error instead of silently encrypting to a key someone else holds. If you would rather warn and continue, I will soften it to a ::warning:: — but the run's results would then be unreadable by the user and readable by whoever holds that key, so I think failing is right.
  • the workflow restores its own scripts/ and results_public.pem from git before the encrypt steps, so a modified script cannot run as the runner even if a grant is widened again later.

Test plan

  • bash -n on both run_agent.sh and collect.sh.
  • bash scripts/collect.sh guard exercised end to end against a mocked gh/openssl with a canary archive: a ../escape member is refused, a symlink member is refused, a clean archive extracts normally.
  • The YAML parses (python3 -c 'import yaml,sys; yaml.safe_load(open(sys.argv[1]))').
  • The workflow itself has not been run in this fork (no emulator, no dispatch rights on your repo). The tool grant change is the part worth watching on the first real run: if a brief uses a command I did not list, it will be refused rather than silently allowed. The briefs I read use adb, screen.py, type.py/gesture.sh, sleep, ls, cat and mkdir — I listed those.

Not in this PR

S3 (BUILD_ARGS visible to the app's build code) — your call, options are in #31.

Six medium/low findings are also in the issue and not here.

The app under test writes the text the agents read, so the agent's tool
grants and the scripts it can reach are trust boundaries.

- Android and iOS agents: Read/Write/Edit were unqualified, so the agent
  could read .git/config and the runner's environment, and write to the
  workflow's own scripts. Read is now the files the briefs name
  (AGENT_BRIEF.md, briefs/, personas.json, bug_report.md, results/), writes
  stay in results/, and cat is narrowed to bug_report.md and results/ — the
  same shape as the web agent's grant.
- The app id read from the APK reaches `adb shell`, which joins its
  arguments into one command the device shell parses. Refuse an id that is
  not a package name (scripts/device_state.py already does this check).
- Restore scripts/ and results_public.pem before running
  encrypt_results.sh: the agent (and the app's build code) can write to the
  workspace, and the encrypt step runs a script by name afterwards.
- collect.sh: decrypt to a file, refuse members that escape the output
  directory or that are symlinks, then extract.
- Pass `framework` through env instead of interpolating it into the `run:`
  body, where a double quote turns it into shell.
- Fail closed when results_public.pem is still the template's key: an
  unset-up clone encrypts to a key the user does not hold.

Tests: python3 -m unittest discover -s tests -q (277 passed, 3 skipped),
bash -n and shellcheck -S warning on every script, and collect.sh run
against a mocked gh with a symlinked archive, a `../` member, and a clean
archive.
@pierridotite
pierridotite merged commit f1a4042 into pierridotite:main Nov 27, 2026
2 checks passed
pierridotite added a commit that referenced this pull request Nov 27, 2026
…sona checkouts; Deutsch in docs language lines; BUILD_ARGS note
@pierridotite

Copy link
Copy Markdown
Owner

Thanks, this is a careful audit and the fixes are real. Merged, with a small follow-up: the template key check skips this repo itself (that key is mine, my own runs use it), the two cat rules are gone since Read already covers those files, and the persona checkouts now use persist-credentials: false, because adb push could still copy .git/config to the phone. For BUILD_ARGS I went with option (a): the docs now say not to put long-lived secrets in it.

@amirkhakshour

Copy link
Copy Markdown
Contributor Author

Thanks, this is a careful audit and the fixes are real. Merged, with a small follow-up: the template key check skips this repo itself (that key is mine, my own runs use it), the two cat rules are gone since Read already covers those files, and the persona checkouts now use persist-credentials: false, because adb push could still copy .git/config to the phone. For BUILD_ARGS I went with option (a): the docs now say not to put long-lived secrets in it.

Read 22b9f32. The three changes are in the right places.

persist-credentials: false is the one that actually closes the token path. I could not close it from the tool grant: adb takes a path as an argument, so adb push .git/config was allowed no matter what the Read rules said. With no token in that file, the push copies nothing useful.

Removing the two cat rules is right. Read already covers bug_report.md and results/, and every Bash rule is another surface the app's text can aim at.

The template-key exception is safe as written because the workflow only triggers on workflow_dispatch. A fork that dispatches it runs with GITHUB_REPOSITORY set to the fork, so a fork that never ran ./setup.sh still fails closed instead of encrypting to your key. If you ever add a pull_request trigger, that comparison stops being enough, because a fork PR runs in the base repo's context and would carry your name; at that point it needs github.event.pull_request.head.repo.full_name == github.repository.

On BUILD_ARGS I agree with (a). A docs note is the only real control here: nothing in the workflow can keep a value out of the build step's environment when the build command comes from the app's own code. The only enforcement would be to stop passing a long-lived secret there at all.

Nothing else from me on this one. The six medium/low findings are still written up in #31. Tell me if you want the mechanical ones as a second PR or would rather have them as a triage list, and I will do that.

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