Skip to content

fix(app-control): write affected.json fresh, never through a link - #13838

Merged
kyle-sexton merged 2 commits into
mainfrom
fix/13710-affected-nofollow
Nov 6, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
fix/13710-affected-nofollow

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #13710

Summary

Capture run 42292050330, the first after PR 13825, drove nothing. Its summary says: "affected blocked: affected_features.py could not run (permission for the command was denied in this unattended session); no entry point driven". run-e2e finds what to drive through drive's Affected step (plugins/testing/skills/run-e2e/SKILL.md:86), so with that script refused the capture never launches the app.

PR 13825 dropped the capture's python3 -I rule after claude-security-review found that the script's open(<out>/affected.json, "w") follows a link a pull request's head or its sandbox can plant, redirecting the write into a .base script the leg may run (thread). This PR removes that route in the script itself, then restores the rule.

Fix

  • plugins/app-control/scripts/affected_features.py: before the write, any entry at affected.json is unlinked, which removes a link and never its target. The file is then created with O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW. A link planted again between the two calls makes O_EXCL fail, so the step reports blocked and writes nothing.
  • .github/workflows/pr-verify-capture.yml: Bash(python3 -I ${{ github.workspace }}/.base/plugins/app-control/scripts/affected_features.py *) is back, main's copy only, by absolute path. The Bash-fence comment says why it is safe.
  • The security lane's second proposal, running .base scripts from root-owned copies, is not taken. The routes it guards are already closed:
    • The leg's file tools cannot write .base: the absolute Edit(/${{ github.workspace }}/.base/**) deny rule, and the probe's write-link check.
    • The sandbox mounts .base read-only, so it cannot write it either.
    • A hard link from the sandbox's capture-run into .base fails, since they are separate bind mounts. link(2), EXDEV: "link() does not work across different mounts, even if the same filesystem is mounted on both".
    • The script's own write was the one route left, and this PR closes it.

Verification

  • bash plugins/app-control/scripts/affected_features.test.sh: all passed. It has a new case each for a symbolic and a hard link left at affected.json: the link is replaced and its target is unchanged. On main's script, both new cases fail.
  • node --test .github/scripts/pr-verify/workflow.test.mjs: 80 passed. The absolute python3 -I form is allowed; forms without -I, a relative path and the head's copy stay refused.
  • scripts/check-affected.sh --tests: 15 passed, 94 skipped.
  • This PR's own capture runs main's workflow, so it does not exercise the fix. The capture after the merge grades fix(pr-verify): route the capture's outer leg through the key proxy and narrow its Bash #13710 done-when 3 and checks that it drove the plugin the test PR changed.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01RMa441b9qec43NvaTyiY2Z

kyle-sexton and others added 2 commits November 6, 2026 16:03
…d let the capture run it

Capture run 42292050330 drove nothing: run-e2e needs drive's Affected step
and the leg could not run affected_features.py. The script now removes any
link at its affected.json and creates the file with O_EXCL|O_NOFOLLOW, so a
link planted by a pull request's head or its sandbox cannot redirect the
write. The capture's python3 -I rule for main's copy comes back.

Refs: #13710

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMa441b9qec43NvaTyiY2Z
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 6, 2026 21:13
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-06T21:13:07.658320Z
We couldn’t complete this review. Comment @codex review to try again.
e1020f2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

claude-review reviewed e1020f2d9af577c3f4e7e67d8b289e87169c151f: read 5 of 5 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #13838, write affected.json fresh and never through a link

No findings. I read every hunk of all 5 changed files. This is the lane's first review of the pull request, so all findings were in scope, not only blocking ones. No settled threads were supplied.

What changed

  • The script. plugins/app-control/scripts/affected_features.py now does the following before it writes affected.json:
    • It removes any entry already at that path. Removing a link deletes the link, not the file it points to.
    • It then creates the file with O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW (L228-L238).
    • Before this change, both a symbolic link and a hard link at that path let the open(..., "w") write land in the linked file. The new code closes that route.
    • If someone plants a link again between the delete and the create, O_EXCL makes the create fail. That error is not caught, so the script exits non-zero with a traceback instead of writing. That fails closed, which is what the PR description says.
  • The test. affected_features.test.sh adds one case for a symbolic link and one for a hard link. Each checks four things: exit 0, the link's target is unchanged, the path is no longer a link, and the new file is valid JSON. Both cases would fail against the old open(path, "w"), because the write would change the target's contents. The fix therefore has a test that can fail.
  • The workflow rule. The Bash(python3 -I <abs>/.base/.../affected_features.py *) rule in pr-verify-capture.yml uses the same unquoted python3 -I ${CLAUDE_PLUGIN_ROOT}/scripts/affected_features.py form that drive's SKILL.md:150 tells the agent to run. That skill does not quote the path, so a single rule is enough.
  • The workflow test. workflow.test.mjs updates the expected allow rules. It moves the absolute -I command from the refused list to the allowed list, and it still refuses the form without -I, the relative path and the head's copy.
  • The changelog fragment. .changes/app-control/... declares bump: patch, which fits a bug fix with no interface change.

Path-scoped rules: .claude/rules/ruff-pin.md matches the changed .py file. It only says how to run lint, so nothing in it applies to this change.

Closing issue: none. The PR says Refs: #13710, not a closing keyword, so there are no acceptance criteria to check.

Not checked: the PR body's verification results (test runs and pass counts) were reported by the author. I could not run them, so they are unconfirmed.

Security: this repository runs a separate security lane, so I left the trust-boundary questions to it. Examples are the --out directory itself being a link, or --out pointing into .base.

Spend: restoring the affected_features.py rule lets later capture runs drive the app, so those runs will use more turns and API usage. That is prepaid usage, not a hold.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

claude-security-review reviewed e1020f2d9af577c3f4e7e67d8b289e87169c151f: read 5 of 5 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #13838, no security issues found

This is the first review of this PR (blocking only: no). I read every hunk of all 5 changed files. One of them, .github/workflows/pr-verify-capture.yml, is on a trusted path, so I read the whole change and the step it gates (Capture the change, L1066-L1206).

What changed. affected_features.py now removes anything already sitting at <out>/affected.json, then creates a new file with O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW (L228-L237). With that in place, the capture leg gets back its allow rule Bash(python3 -I ${{ github.workspace }}/.base/plugins/app-control/scripts/affected_features.py *) (L1171).

What I checked:

  • Symlinks and hard links at the output file. Deleting the entry removes only the link, never the file it points to. If someone plants a new link between the delete and the open, O_EXCL makes the open fail, and the script exits non-zero without writing anything. If --out is itself a symlinked directory, the script can only create a new file named affected.json in the target directory. The name is fixed, so it cannot overwrite a .base script that these rules run. That closes the route the earlier review reported on PR 13825.
  • How wide the restored rule is. The * lets the leg pass any arguments.
    • --out: the leg can create directories and create or replace a file named affected.json anywhere the runner user can write. That goes past the file-tool fence. However, nothing trusted reads affected.json outside the run directory: its only readers are the drive, confirm and run-e2e skills, which read it from the run directory. So I found no path to a leak, a compromise or a charge.
    • --hub, --skill-dir and --repo can name any path. But the script only uses hub lines that match ^- .*\|\s*(features/|entry points:) and have a sources: field (L26, L85-L94). It reads feature files only as features/*.md inside the skill directory (L128-L132). A credential or environ file cannot get its content into the output that way.
  • Git in a head the leg can edit. Git runs with core.fsmonitor=false, --no-ext-diff and --no-textconv on a tree-to-tree diff, with every GIT_* variable stripped from the environment. The existing rules already let the leg run git (status, diff) in that head.
  • Python. -I keeps the script's directory and the current directory off the module search path and ignores PYTHON* variables. Forms without -I, relative paths and the head's copy of the script stay refused, as workflow.test.mjs asserts.
  • Trust controls. This file is not one of the listed trust controls (trusted trigger, lane token, kill switch, token-broker signer, merge holds). The leg still holds only the key proxy's per-run client key (api-key: ${{ steps.proxy.outputs.client-key }}, L1131). The permissions:, if: and deny rules in this step are unchanged. I found no widening of who is trusted, of what a token can do, or of what untrusted text reaches a credentialed lane.
  • Instruction text. The only removals are code and test comments. No standing instruction is deleted or narrowed.
  • PR description. It contains no embedded instructions aimed at this review.
  • Plugin manifests. The diff changes none.

critical-findings: 0

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit dd3be4f Nov 6, 2026
75 checks passed
@kyle-sexton
kyle-sexton deleted the fix/13710-affected-nofollow branch November 6, 2026 21:29
kyle-sexton added a commit that referenced this pull request Nov 6, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMa441b9qec43NvaTyiY2Z
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.

1 participant