Skip to content

fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754

Closed

Description

@dan-petty

Problem Statement

.github/workflows/update-prs.yml runs devops pr update <PR> for any pull request comment whose body starts with /update or /sync (job if: at update-prs.yml:37-42). The job holds contents: write, pull-requests: write and issues: write (update-prs.yml:45-48) and never checks who commented; author_association appears nowhere under .github/, src/ or tests/. The repository is public, so anyone with a GitHub account can make the workflow update any open pull request's branch and spend Actions minutes. The file has not changed since v0.2.20 (git log --oneline -- .github/workflows/update-prs.yml shows only c5b8989), so nothing of this item is delivered.

The comment path interpolates only numeric or repository-controlled values into run: (github.event.comment.id at line 74, github.repository at lines 75 and 83, github.event_name at line 82, github.event.issue.number at line 86, github.ref_name at line 108), so there is no script injection today. The workflow_dispatch inputs, however, are interpolated straight into the run: script with ${{ }} (dry_run at line 91, pr_number at line 94, base_branch at line 95). Only people with write access can reach workflow_dispatch, so this is a hardening gap rather than an exploitable one, but uv run actionlint (ci.yml:65-66, the actionlint row of devops ci at src/devops_cli/commands/ci.py:436-440) does not flag it, and the workflow contract test planned by #697 (docs/agent/tasks/task-697-*.md:16, which names update-prs.yml:74-86 as the violation) and the zizmor template-injection rule #861 plans to enforce (docs/ROADMAP.md:1206, "report-only until the five sites move their GitHub Actions expressions into env:") both fail on any expression inside run:.

Nothing in src/ posts /update or /sync comments (grep -rnE "[\"' ]/(update|sync)\b" src/devops_cli matches nothing; the bare substrings match only Argo /sync API URLs and the pulls/{n}/update-branch endpoint), so restricting the comment trigger breaks no in-repo caller.

This is step 1 of the required-checks sequence (owner decision D3). It lands before update-prs.yml is given any privilege beyond what it holds today: #984 (D3 step 2) then adds actions: write to this job and makes it dispatch ci.yml, and #842 (D3 steps 3-5) confirms that live and turns the required checks on.

Proposed Solution

One pull request that changes only .github/workflows/update-prs.yml, one new test module, the task file and a changelog fragment:

  1. Collaborator guard. Extend the job-level if: (update-prs.yml:37-42) so the issue_comment branch also requires contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association). The guard lives in the job if:, so an unauthorized comment produces a skipped job and no runner time; there is no reply or reaction to it. The push and workflow_dispatch branches of the condition are untouched.
  2. No expressions inside run:. Move every ${{ }} that is currently inside a run: block of update-prs.yml to the step's env: and read it as a shell variable, following the pattern already used by cleanup-devcontainer.yml:44-52 (INPUT_PR_NUMBER: ${{ github.event.inputs.pr_number }} in env: at line 46, then "$INPUT_PR_NUMBER" in run: at line 52). That covers the three dispatch inputs (lines 91, 94, 95) and the six repository-controlled values (lines 74, 75, 82, 83, 86, 108). GH_TOKEN (lines 72, 80) and the concurrency.group expression (line 30) are already outside run: and stay as they are. The shell logic ([ "$DRY_RUN" = "true" ], -n tests, argument arrays) does not change, so push and dispatch behaviour is identical. The four uv run devops pr update invocations stay one-line calls, which is the shape feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984 relies on when it appends --dispatch-ci to each.
  3. Contract test. Add tests/test_workflow_contracts.py (the module name feat(github): defect prs carry their hardening readiness blocker and post-merge audit #697 and fix(github): supply-chain claims made true — live Dependabot, zizmor and workflow invocation contracts #861 already cite, and the one feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984 extends with its permissions and --dispatch-ci assertions; it starts with these assertions and imports nothing beyond PyYAML and pathlib, like the workflow tests at tests/test_ci.py:538-628):
    • the update-pull-requests job if: references github.event.comment.author_association and each of OWNER, MEMBER, COLLABORATOR, and still contains github.event_name == 'push' and github.event_name == 'workflow_dispatch';
    • no run: value in any step of update-prs.yml contains the substring ${{;
    • a mutation case for each: the first assertion fails on the workflow with the author_association clause removed, the second fails when ${{ github.event.inputs.pr_number }} is put back into a run: string.
  4. Changelog fragment changelog.d/754.md under ### Security (house style per changelog.d/README.md), and the task file docs/agent/tasks/task-754-collaborators-only-trigger-pr-updates.md written as Done in the delivering commit.

Scope

  • Files changed: .github/workflows/update-prs.yml, tests/test_workflow_contracts.py (new), docs/agent/tasks/task-754-*.md (new), changelog.d/754.md (new).
  • Allowed associations: OWNER, MEMBER, COLLABORATOR (from the original body). The repository is user-owned, so MEMBER never matches today; it is harmless and keeps the guard correct if the repository moves to an organization. Any account without write access, including bots, is excluded.
  • The permissions: block is not widened here; actions: write is feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984's change.
  • Effort: low. Value: high.

Key Questions

All answered; none open.

Acceptance Criteria

  • uv run pytest tests/test_workflow_contracts.py -q passes. The module parses .github/workflows/update-prs.yml with PyYAML and asserts the update-pull-requests job if: references github.event.comment.author_association, OWNER, MEMBER and COLLABORATOR, and still contains github.event_name == 'push' and github.event_name == 'workflow_dispatch'.
  • The same module asserts that no run: value in any step of update-prs.yml contains ${{. After the change, grep -n '\${{' .github/workflows/update-prs.yml matches only concurrency.group (line 30) and env: value lines (the job if: and the Acknowledge comment trigger step if:, line 70 at HEAD, contain no ${{).
  • The module's two mutation cases pass: removing the author_association clause from the parsed condition makes the guard assertion fail, and putting ${{ github.event.inputs.pr_number }} back into a run: string makes the no-expression assertion fail.
  • uv run actionlint exits 0 on the changed workflow.
  • uv run devops ci passes offline; the new tests spawn no process and open no socket (the tests/conftest.py:99 network guard stays silent), and uv run pytest --durations=5 tests/test_workflow_contracts.py shows each test under 1 s.
  • git diff --stat main...HEAD lists only .github/workflows/update-prs.yml, tests/test_workflow_contracts.py, docs/agent/tasks/task-754-*.md and changelog.d/754.md; CHANGELOG.md and docs/ROADMAP.md are untouched (devops pr check-readiness blocks either on a release/* base, src/devops_cli/commands/pr.py:1648-1668).
  • git diff of update-prs.yml changes no character of the push or workflow_dispatch branches of the job if:; the on: block, the permissions: block (contents, pull-requests, issues; no actions: key) and the step order are unchanged, and grep -c 'uv run devops pr update' .github/workflows/update-prs.yml still prints 4.
  • Pending a person: after merge, comment /update on an open PR from the owner account, then run gh run list --workflow update-prs.yml --limit 3 and see a completed run and the rocket reaction on the comment. When an account without write access next comments /update or /sync on a PR, the Actions tab lists that run as skipped. GitHub computes author_association server-side, so no offline test exercises the live guard.

Out of Scope

Dependencies

Readiness check (2026-10-04)

Checked at the release/v0.2.26 tip (b61e5a0). update-prs.yml is unchanged (its history is still only c5b8989), so every update-prs.yml line, the job if: (:37-42) and the nine ${{ }} sites inside run: hold. tests/test_workflow_contracts.py does not exist yet. Corrections:

The acceptance criteria are unchanged. The item agrees with the rules in force: offline tests, a changelog.d fragment, and one PR that closes #754 only.

Activity

  1. added
    type/security
    priority/p1-high
    scope/ci
    on Sep 30, 2026
  2. added this to the v0.2.27 milestone on Oct 1, 2026
  3. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Placement (2026-10-01): v0.2.27. Value High, Effort Low. Not Ready yet.

    Checked against release/v0.2.24 at d38251e. What stops it being Ready:

  4. added a commit that references this issue on Oct 1, 2026
  5. dan-petty-bot commented on Oct 5, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1191, merged into release/v0.2.27 as 6329396.

    Summary

    • Restrict .github/workflows/update-prs.yml issue_comment trigger to repository collaborators (OWNER, MEMBER, COLLABORATOR), ensuring unauthorized PR comments produce a skipped job without consuming Actions runner minutes.
    • Move GitHub Actions expressions (${{ ... }}) out of run: script bodies into step env: variables to eliminate shell injection attack surfaces.
    • Add comprehensive workflow contract tests in tests/test_workflow_contracts.py verifying collaborator authorization, expression isolation, permission boundaries, and mutation cases.

    Closes #754

    4 file(s) changed.

    How it was verified

    Check runs at e907e90:

    • Prune PR DevContainer Images: pass
    • Analyze (python): pass
    • CodeQL: pass
    • Dependency Freshness: skipping
    • Service Image: skipping
    • Static Analysis: pass
    • Analyze (actions): pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-754-collaborators-only-trigger-pr-updates.md:

    • uv run pytest tests/test_workflow_contracts.py -q passes, verifying that the update-pull-requests job condition requires github.event.comment.author_association matching OWNER, MEMBER, or COLLABORATOR, while preserving push and workflow_dispatch events.
    • Contract tests verify that no step in update-prs.yml interpolates expressions inside run: blocks, with occurrences restricted to concurrency.group and step env: variables.
    • Mutation tests verify that removing the author association check or re-introducing inline expressions into run: blocks causes immediate test failure.
    • uv run actionlint exits 0 on .github/workflows/update-prs.yml.
    • uv run devops ci passes offline with 100% green status across all quality gates.
    • git diff against base branch lists only .github/workflows/update-prs.yml, tests/test_workflow_contracts.py, docs/agent/tasks/task-754-collaborators-only-trigger-pr-updates.md, and changelog.d/754.md.
    • update-prs.yml preserves the 4 uv run devops pr update invocations, step order, and minimal permissions.
    • Pending a person: after merge, comment /update on an open PR from the owner account, then run gh run list --workflow update-prs.yml --limit 3 and see a completed run and the rocket reaction on the comment. When an account without write access next comments /update or /sync on a PR, the Actions tab lists that run as skipped.
  6. added a commit that references this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/citype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions