What Causes Trusted Automation to Execute?
In Part 4, we looked at why the runner itself forms part of the GitHub Actions security boundary.
But there is another consideration that sits slightly earlier in the execution lifecycle.
What causes a workflow to run in the first place?
GitHub Actions is event-driven. We define workflows, associate them with events, and allow GitHub to execute them when those events occur.
A commit is pushed. A pull request is opened. Someone leaves a comment. Another workflow completes.
Most of this feels like straightforward automation configuration.
Except that not all events originate from equally trusted sources, and not all workflows execute with the same privileges.
A workflow triggered by a push to a protected branch has a different trust context from one triggered by a pull request submitted from an external fork.
Likewise, a workflow responding to a comment on an issue may be executing trusted automation, but the event that caused it to run, and the data supplied with that event, may have originated from someone with no meaningful access to the repository.
This is where workflow triggers become security relevant.
The trigger determines how execution begins, but also influences the trust context in which that execution takes place.
And some of the more dangerous GitHub Actions configurations arise when we fail to maintain the distinction between those two things.
Pull Requests Are Untrusted Input
Consider a typical CI workflow.
A contributor opens a pull request, GitHub triggers a workflow, and the proposed changes are checked out, built, and tested.
For a public repository, that contributor could be someone the maintainers have never interacted with before.
They control the changes being proposed, including potentially build scripts, tests, dependencies, configuration files, and other content that the workflow may execute.
GitHub accounts for this in its handling of the pull_request event.
For pull requests originating from forks, GitHub ordinarily provides a read-only GITHUB_TOKEN, withholds repository secrets, and applies approval policies that can restrict execution.
These controls exist for a reason.
Building or testing a pull request is, in practical terms, potentially executing code supplied by the person who opened it.
That code needs to run somewhere, but it should not automatically inherit the same privileges as trusted repository automation.
There are qualifications, of course. Organisations can configure aspects of fork workflow permissions, and private repositories have additional policy options. The underlying runner environment also matters, as discussed in Part 4.
But the default security model recognises a useful distinction.
We want to validate proposed changes without necessarily trusting the person proposing them.
Problems start when we attempt to work around that distinction.
The Subtle Danger of pull_request_target
GitHub provides another pull request trigger called pull_request_target.
At first glance, the difference in naming is fairly unremarkable.
The difference in execution context is not.
Unlike a conventional pull_request workflow, pull_request_target runs the workflow definition from the base repository’s default branch, rather than the pull request’s merge commit.
Because the workflow definition comes from the trusted base repository, GitHub can make the base repository’s secrets and a potentially write-capable GITHUB_TOKEN available to it.
This enables legitimate automation that needs to respond to pull requests from forks.
For example, automatically labelling incoming pull requests, updating metadata, or posting authenticated comments.
Crucially, the pull request’s proposed code is not executed by default.
The problem appears when someone decides that this privileged workflow should also build or test the code submitted in the pull request.
Consider the following simplified example:
# INSECURE EXAMPLE
on:
pull_request_target:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@<full-commit-sha>
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Run tests
run: make test
The intention seems reasonable.
We want to test the proposed changes, perhaps while retaining access to a private package registry or another resource requiring credentials.
But look at what we have actually done.
We have started a workflow in the privileged context of the base repository, explicitly checked out code controlled by the pull request author, and then executed instructions from that checkout.
The Makefile is no longer necessarily trusted. Neither are the dependencies, scripts, or configuration files that the test process might invoke.
An external contributor may now have a path to executing their code in an environment with privileges they were never intended to receive.
This class of vulnerability is commonly referred to as a pwn request.
GitHub has introduced additional protections against unsafe pull request checkouts in this context, but the underlying architectural problem remains important to understand.
pull_request_target is not inherently unsafe.
Combining its privileged execution context with untrusted code execution is where the boundary breaks.
Untrusted Input Is Not Limited to Source Code
There is another variation of this problem that is arguably easier to overlook.
We tend to associate untrusted input with source code submitted through pull requests.
But GitHub events contain considerably more information than repository changes.
Pull request titles, descriptions, branch names, commit messages, issue comments, and other event metadata may all contain values controlled by external contributors.
Those values become available to workflows through the GitHub context.
Consider a workflow that performs some basic validation on a pull request title:
- name: Check PR title
run: |
title="${{ github.event.pull_request.title }}"
echo "$title"
This looks harmless enough.
Except that GitHub evaluates expressions before passing the resulting script to the shell.
The pull request title is therefore inserted directly into the generated shell script, where specially constructed content may alter how that script executes.
Quoting the expression inside the YAML does not make it safe.
A safer approach is to pass the value through an environment variable:
- name: Check PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "$PR_TITLE"
Now the event value is supplied as data rather than being interpolated into the script itself.
That does not remove the need to handle the value appropriately wherever it is subsequently used, but it avoids this particular injection pattern.
The broader point is that an attacker does not necessarily need to modify a workflow file, introduce a malicious Action, or compromise a dependency.
Sometimes they only need to control a value that trusted automation subsequently interprets as an instruction.
This becomes particularly significant when the workflow is executing with elevated permissions.
Separating Untrusted Execution From Privileged Operations
There are legitimate situations where a CI process needs both to validate untrusted contributions and perform an operation that requires additional permissions.
For example, we might want to build and test an external pull request, generate a coverage report, and then publish a comment containing the results.
The mistake would be assuming that all of those operations need to happen within the same privileged execution context.
They do not.
GitHub’s workflow_run event provides one mechanism for separating these concerns.
A first workflow, triggered by pull_request, can execute the untrusted code with restricted permissions and produce a result.
A second workflow, triggered by completion of the first, can perform the privileged operation.
Importantly, a workflow_run workflow can receive secrets and write permissions even when the workflow that triggered it could not.
That is what makes this separation useful.
It is also what makes the interface between the two workflows security-sensitive.
Suppose the first workflow uploads a coverage report as an artifact.
The second workflow downloads that artifact and uses its contents to publish a comment.
We still need to consider what happens to the data crossing that boundary.
If the privileged workflow blindly executes a downloaded script, trusts an attacker-controlled filename, or interprets artifact contents as commands, we have simply moved the vulnerability from one workflow to another.
The artifact is an output of untrusted execution.
Completing the first workflow does not somehow make that output trustworthy.
The privileged workflow should consume narrowly defined results, validate their structure, establish that they belong to the expected run and pull request, and avoid executing content received from the untrusted job.
This is a fairly useful principle beyond GitHub Actions.
Separating privileged and unprivileged execution only helps if we also control what crosses between them.
Reusable Workflows Do Not Remove the Trust Problem
Reusable workflows introduce another dimension to this discussion.
They are an attractive way to standardise automation across an organisation.
Rather than maintaining separate implementations of build, scan, release, or deployment logic in dozens of repositories, we can centralise common workflows and expose them through workflow_call.
From a platform engineering perspective, there is considerable value in this.
We can improve consistency, reduce duplication, and provide developers with a supported approach to common delivery tasks.
But centralising implementation does not automatically centralise trust.
A reusable workflow executes in the context of its caller. Its github context is associated with the calling workflow, and the GITHUB_TOKEN permissions available through the call can be maintained or reduced, but not elevated through the reusable workflow chain.
Callers can also pass inputs and secrets, including inherited secrets where supported.
Consider what that means for a reusable deployment workflow.
The implementation might live in a centrally managed repository and be maintained by a small group of trusted platform engineers.
But if the workflow accepts a caller-controlled script, command, deployment target, or other value that can influence execution, the security of the central implementation still depends on how those inputs are handled.
Similarly, a reusable workflow that accepts inherited secrets may have access to substantially more sensitive information than its implementation actually requires.
A shared workflow is not a security boundary simply because it lives in a different repository.
We still need to understand which callers can invoke it, which permissions and credentials they can supply, what inputs it accepts, and whether those inputs can influence privileged execution.
This is particularly important when reusable workflows become part of an organisation’s approved delivery platform.
The more widely they are adopted, the more consequential an unsafe interface can become.
Standardisation gives us leverage.
It can also standardise a mistake.
Review What Crosses the Boundary
One way I find useful to reason about these configurations is to stop looking at workflow files individually and instead follow the execution path.
Start with the event.
Who can cause it to occur, and how much control do they have over the data associated with it?
Then look at the workflow.
Which version of the workflow definition executes? What permissions does it receive? Which secrets are available, and what infrastructure will run it?
Finally, follow any information or execution that crosses into another context.
Does the workflow check out code from a fork? Does it interpolate event metadata into shell commands? Does it download artifacts produced by another workflow? Does it invoke reusable automation with caller-controlled inputs or inherited secrets?
These are the points where assumptions about trust need to be explicit.
The practical controls follow from understanding those relationships:
- Use
pull_requestfor untrusted contribution validation unless a more privileged event is genuinely required. - Avoid executing pull request code inside privileged
pull_request_targetworkflows. - Treat event metadata as untrusted input, including seemingly harmless values such as titles and branch names.
- Keep privileged operations separate from untrusted build and test execution.
- Treat artifacts and outputs from untrusted workflows as data that requires validation, not as trusted instructions.
- Keep reusable workflow interfaces narrow, with explicit permissions, inputs, and secret requirements.
- Review the runner’s infrastructure permissions and network access alongside the workflow trigger.
These measures address different aspects of the same problem.
They help prevent someone who controls a relatively low-trust event or input from influencing execution in a context that carries substantially greater privileges.
Trust Is Established Before the First Step Runs
It is easy to spend considerable effort reviewing what happens inside a GitHub Actions job while giving relatively little attention to why that job is allowed to execute.
But the event that starts a workflow is part of its threat model.
A secure runner does not compensate for a privileged workflow executing attacker-controlled code. Pinning an Action does not make untrusted event metadata safe to interpolate into a shell script. And moving logic into a reusable workflow does not remove the need to understand who can call it and what they can pass into it.
These are not independent concerns.
They are different points in the same execution chain.
Across this series, we have considered which code we trust, how we control its dependencies, and the environment in which that code executes.
Workflow triggers add another question.
Who can cause that trusted automation to run, and what control do they have over what happens when it does?
That question deserves as much attention as the workflow implementation itself.