No privileged workflow runs untrusted code
github/no-untrusted-checkout@v1
No workflow triggered by pull_request_target, issue_comment or workflow_run checks out a revision of its own choosing, or passes the request's revision into a command.
| Id | github/no-untrusted-checkout |
| Version | v1 |
| Category | github |
| Default severity | error |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | github |
Collectors
This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.
| Collector | Gathers | Inputs it is given |
|---|---|---|
github | What GitHub itself reads out of the repository: the Actions workflows in .github/workflows, read as they are written, and the CODEOWNERS file, read as rules. For a workflow, which events start it, what token permissions it hands a job, which runner each job asks for, and every action a step reaches for and how tightly it is pinned. For CODEOWNERS, every pattern in file order with the owners it names, and the owners that apply to the paths a guardrail asks about, resolved the way GitHub resolves them, where the last rule to match a path is the one that owns it. Names and shapes only, never a secret, an input value or an environment value. | workflows |
The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.
Configuration
{
"guardrails": {
"failOn": "error",
"checks": [
{
"use": "github/no-untrusted-checkout@v1",
"severity": "error",
"with": {
"workflows": ".github/workflows/*.yml,.github/workflows/*.yaml"
},
"exemptions": []
}
]
}
}Inputs
| Input | Description | Default | Environment variable |
|---|---|---|---|
workflows | Comma separated globs naming the workflows to read. | .github/workflows/*.yml,.github/workflows/*.yaml | GUARDRAIL_INPUT_WORKFLOWS |
How to fix
Split the workflow. Do the untrusted work under pull_request, which runs without your secrets, and keep the privileged trigger for the step that needs the token, checking out only the base:
on: pull_request_target
jobs:
label:
steps:
- uses: actions/checkout@<sha>pull_request_target runs with the repository's secrets and a writable token, using the workflow definition from the base branch. Checking out the pull request head under it hands both to whoever opened the pull request. It is the single most exploited CI misconfiguration there is.
The guardrail reads the input names a checkout step declares, not their values, so any ref under one of these triggers is flagged. Checking out the base explicitly is the rare legitimate case: give that step no ref at all, because under pull_request_target that already checks out the base.
More in github
github/actions-pinned-by-digest. Every third-party action a workflow uses is pinned to a full commit sha, not to a tag or a branch.github/codeowners-catch-all.CODEOWNERShas a rule matching every path, so even a file nobody thought about has an owner.github/codeowners-no-unowned-rules. No rule inCODEOWNERShas an empty list of owners, which would remove ownership from everything it matches.github/codeowners-owners-per-rule. Every rule inCODEOWNERSnames at least the minimum and at most the maximum number of owners, so review neither depends on one person nor becomes everybody's problem.github/codeowners-parses. Every line ofCODEOWNERSthat is not a comment is a rule GitHub can read, so no ownership is silently lost to a line GitHub ignores.github/codeowners-present. The repository has aCODEOWNERSfile where GitHub looks for one, with at least one rule, so every change has someone to review it.github/codeowners-team-owned. Every rule inCODEOWNERSnames at least one GitHub team, so ownership outlasts the people currently on it.github/job-timeout-set. Every job declares how long it may run, so a hung job is stopped instead of holding a runner until GitHub's own limit.