Free security runbook · GitHub Actions

GitHub Actions: untrusted input, token scope, and the fork that runs your workflow

A workflow is a small program that runs with a token, on a runner, triggered by events a stranger can shape. The review comes down to three questions: what can this job write, whose text does it interpolate, and which trigger runs it with secrets in scope.

This page is free and defensive only. It covers the inventory, the trigger boundary, the token default and the dependency surface — the changes that make a compromised workflow a contained incident instead of an account takeover.

Scope: reviewed from the GitHub Actions security documentation, no live reproduction
Verified against the GitHub Actions security hardening, token authentication, workflow syntax and OpenID Connect documentation on 2026-12-03. This page describes defensive configuration and uses no working payloads. Check the behaviour against the runner image and Actions version you actually use.
Read the state

Four facts before the audit

The trigger is the trust boundary

A workflow triggered by pull_request from a fork gets no repository secrets and a read-only token. pull_request_target runs in the base repository's context, with secrets available, and is not the same workflow under a different name.

Event context is data, not code

Issue titles, branch names, commit messages and PR bodies are written by whoever opened them. Interpolated directly into a run: block, they are shell text before your script starts.

Token scope is a setting

permissions: at workflow or job level replaces the default. Without it, the token inherits the repository or organisation default, which can be read and write on contents, issues and packages.

Actions are dependencies

A tag is a movable label; a commit SHA is not. Reviewing the version in the comment is not the same as pinning the code that actually runs.

Detect

Inventory the workflows you already have

Command or viewWhat it tells you
gh api repos/$OWNER/$REPO/actions/permissions/workflowThe repository default token permissions. read is the least-privilege baseline; write means every job that does not override it can push.
git grep -n 'pull_request_target' .github/workflowsEvery workflow that runs in the base context. Each one needs a written reason and must not check out the pull request head.
git grep -n 'github.event' .github/workflowsEvery use of event data. The dangerous subset is the one that reaches a run: block or an action input that executes a command.
git grep -n 'permissions:' .github/workflowsWhich workflows declare scope. A missing declaration is not "no permissions"; it is the default.
git grep -nE 'uses: [^ ]+@v[0-9]' .github/workflowsActions pinned to a major tag. Those can be retagged upstream without any change on your side.
actionlint -colorStatic checks for workflow syntax, shell quoting and known context misuse. It finds the mechanical mistakes before a human review.
gh api repos/$OWNER/$REPO/environmentsProtected environments and their reviewers. A deploy job outside one has no approval gate.
gh secret listThe secret names a compromised job could read. You do not need the values to decide that the scope is too broad.
Failure modes

Seven ways a workflow becomes the incident

#Failure modeWhat you seeWhat to do
1pull_request_target that builds the pull requestA workflow added for labelling or commenting also checks out the contributor's code, and the job has secrets and a write token.Keep this trigger to metadata-only jobs. Build untrusted code under pull_request, where secrets are absent.
2Event context interpolated into run:The YAML looks like a template, but the title or branch name is pasted into the shell command line.Pass the value through env: and quote it in the script; never place the expression inside the command text.
3A default write tokenAny step, including a third-party action, can push commits, move tags or edit releases.Set permissions: contents: read at the top and grant the one job that needs write its own scope.
4An action pinned to a tagThe digest changes after an upstream release, and the next run executes code nobody reviewed.Pin to a full commit SHA with the version in a comment, and let Dependabot open the update PR.
5A self-hosted runner on a public repositoryUntrusted jobs run inside your network with whatever the runner host can reach.Use GitHub-hosted or ephemeral runners for public events; keep persistent runners for trusted, protected jobs only.
6A deploy step that runs on forksThe step does not fail; the secret is simply empty, and the deploy reports success or silently skips.Gate jobs on the event and the repository, and fail explicitly when a required secret is missing.
7Artifacts trusted across workflowsA privileged workflow_run job downloads an artifact produced by an untrusted workflow and executes it.Treat artifacts as untrusted input: validate, do not execute, and keep the privileged workflow free of contributor code.
Harden

Changes with the widest effect

LayerChangeEffect
TokenDefault to read-only at the repository or organisation levelEvery workflow that does not ask for more becomes read-only at once, including the ones nobody remembered.
JobDeclare permissions: per jobThe write scope exists only where the job needs it, and only for the life of that job.
TriggerUse pull_request for anything that runs contributor codeNo secrets, read-only token, and a fork cannot reach the base repository's credentials.
InputMove expressions into env: before the script uses themThe shell receives a variable value instead of command text, so quoting and validation can work.
DependencyPin third-party actions to a commit SHAA moved tag cannot change what runs; an update becomes a reviewable diff.
Cloud accessOpenID Connect with a subject condition instead of static keysShort-lived credentials, scoped to a repository and a ref, with no long-lived secret to leak.
Verify

Four drills that prove the boundary

Fork pull request

From a fork, open a pull request that changes a workflow or a script. Confirm the run has no secrets, a read-only token, and no ability to push.

Read-only default

Switch the repository default to read-only and run the full CI set. Any job that fails has a real write dependency that was implicit before.

Pinned action

Pin one third-party action to a SHA and confirm the next run is green, then let the update bot propose the next version.

OIDC trust condition

Change the subject condition in the cloud role and confirm the deploy fails closed rather than falling back to a static key.

FAQ

Questions from the workflow review

Is pull_request_target always wrong?

No. It exists so a workflow can act on a pull request from a fork, for example to label it or post a comment, using the base repository's token. It becomes dangerous when the same job checks out and executes the contributor's code.

We set permissions: read-all. Are we done?

That closes the write path but not the input path. A job can still execute contributor-supplied text with a read-only token. Both controls are needed: least privilege limits the damage, input handling prevents it.

Why does the deploy step pass on forked pull requests?

Because the secret is not provided, and the step did not assert that it exists. Make required configuration explicit, fail when it is empty, and gate deploy jobs on the event and the repository.

Do we need to rewrite every workflow at once?

No. Start with the default token and the triggers that touch secrets, then pin actions and move expressions into env: as each workflow is next edited. The inventory table is the work queue.

Sources

Primary sources

The pipeline is part of the attack surface

The paid runbooks cover adjacent change windows: secrets that reach a build log, a proxy default that hides a broken deploy, and a rollback that has to be rehearsed.

This page is free, no checkout. Paid runbooks are $9.99 each and covered by the 7-day refund policy at /runbooks/refund.