Skip to content

Warn when checkout.ref names an untrusted ref while imported or custom steps run on it (runs branch code on the host) #73080

Done

Description

@kdowswell

Summary

In the agent job, the compiled order is:

  1. Checkout repository (with checkout.ref)
  2. imported steps:
  3. the workflow's steps:
  4. "Checkout PR branch" (PR events)
  5. pre-agent-steps
  6. the sandboxed engine

A common pattern is: a planner job picks a PR branch, checkout.ref: ${{ needs.plan.outputs.branch }}, and a shared toolchain import (steps: - run: ./scripts/setup.sh). That runs the branch's own setup script on the host, outside the sandbox, in the job that later runs the engine with its credential. CodeQL reports it as actions/untrusted-checkout (critical). Nothing in gh-aw warns about it, and the safe pattern isn't documented: leave the checkout on the default branch, let toolchain steps run, then switch branches in the workflow's own steps:.

Implementation plan

  1. Add a compiler warning (in pkg/workflow, alongside the checkout handling in checkout_manager.go). Raise it when checkout.ref is an expression that isn't the default ref (it references needs.*, github.event.*, inputs.*) and the agent job has imported or custom steps:. Message: "[checkout.ref is set to an expression and steps run after it]. [Those steps execute the checked-out ref's code on the host, outside the sandbox]. [Example: keep checkout on the default branch and switch in steps: git checkout -B "$BRANCH" --track "origin/$BRANCH"]".
  2. Docs: in reference/checkout.md and reference/steps-jobs.md, document the agent job's step order and the safe pattern for working on a planner-chosen branch.
  3. Test in pkg/workflow (compiler warning test): warn for checkout.ref: ${{ needs.plan.outputs.branch }} plus an imported steps: file; no warning without steps, or with a literal default-branch ref.

Acceptance criteria

Compiling the pattern above prints the warning, and the docs show the switch-after-steps pattern.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions