Sub topic 2
Why tags and branches are risky: a retagged action runs in your pipeline
This chapter assumes you can read a GitHub Actions workflow (jobs, steps, uses:). It also assumes you know that a Git tag is a name for a commit and that a branch is a name that moves forward as commits are added. By the end you should be able to explain how a changed tag becomes code execution in your pipeline, and which of your secrets that code can reach.
What `uses:` resolves at run time
A uses: line has the form owner/repo@ref. The ref after the @ is a name, not a fixed piece of content. When a job starts, the runner asks GitHub for whatever commit that name points to at that moment. It downloads that commit's files and runs them. Nothing in your repository records which commit you got last time.
A ref can be one of three kinds of name:
| Reference | Example | Who can change what it points to |
|---|---|---|
| Branch | `@main` | Anyone who can push to that branch, on every push |
| Tag | `@v4`, `@v4.2.2` | Anyone who can delete and recreate or force-push the tag |
| Full commit SHA | `@11bd71901bbe5b1630ceea73d27597364c9af683` | Nobody. The SHA is derived from the commit's content |
The first two are mutable. The third is not, and the next chapters build on that difference. This chapter is about the first two.
name: ci
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Branch: changes with every push to main in that repository
- uses: some-org/some-action@main
# Major tag: moved on purpose by the maintainer at each v4.x release
- uses: actions/checkout@v4
# Exact version tag: looks fixed, but can still be moved
- uses: actions/[email protected]Tags are movable by design
Git does not treat a tag as permanent. A tag is a small reference file that holds a commit ID. Deleting it and creating it again, or force-pushing it, changes where it points. Git offers no warning to people who already use the tag.
You can see this on your own machine. The script below creates a throwaway repository, tags a commit as v1, then moves v1 to a different commit. It needs Git 2.28 or later for git init -b.
set -e
rm -rf /tmp/tag-demo && mkdir /tmp/tag-demo && cd /tmp/tag-demo
git init -q -b main
git config user.email [email protected]
git config user.name Demo
echo 'echo "doing the documented work"' > run.sh
git add run.sh
git commit -q -m "release 1.0.0"
git tag v1
echo "v1 points to: $(git rev-parse 'v1^{commit}')"
echo 'echo "sending secrets elsewhere"' > run.sh
git commit -q -am "tampered change"
git tag -f v1
echo "v1 now points to: $(git rev-parse 'v1^{commit}')"
git show v1:run.shThe two printed IDs differ. git show v1:run.sh now prints the tampered script. Nothing about the name v1 changed, so any workflow that says @v1 gets different code the next time it runs.
On GitHub the same thing happens with git push --force origin v1. Whether that push is accepted depends on who is pushing and on whether tag protection rules apply.
Moving tags are a feature too
The movement is not always hostile. Most popular actions publish a floating major tag such as v4. At each v4.x.y release, the maintainer moves v4 to the new commit. Users get bug fixes without editing their workflows. That convenience is exactly the mechanism an attacker would use, and the runner cannot tell the two cases apart.
So the tag v4 means "whatever the maintainer most recently decided to call v4". Even an exact tag like v4.2.2 only means "whatever the repository's tag currently says".
Who can change where a ref points
A ref changes when someone with the right access, or a stolen credential that holds that access, moves it. The usual routes are:
- A maintainer's account is compromised. The attacker has the same push rights as the owner.
- A token or deploy key leaks. A personal access token in a CI log, or a token stolen from another compromised workflow, can carry write access to the action's repository.
- A contributor with write access acts maliciously or carelessly. Write access is often broader than people expect, and it normally includes pushing tags.
- A maintainer hands the repository over. An ownership transfer or an abandoned repository that someone else takes over gives the new owner control of every ref.
- A mistake. A maintainer retags the wrong commit or publishes a breaking change under an existing tag. This is not an attack, but your pipeline breaks the same way.
For a branch the picture is simpler. Any merged pull request or direct push changes what @main runs, so referencing a branch means trusting every future commit to it.
From a changed tag to code in your pipeline
When a ref is moved, the new commit's code runs in every workflow that uses it, at the next run, with no change on your side. No pull request, no diff, and no review happens in your repository.
The action runs inside your job, so it has the same reach as any other step in that job. Depending on how the job is configured, that includes:
- The
GITHUB_TOKENfor the job, with whatever permissions the workflow grants it. - Any secret you pass to that step through
env:orwith:. Secrets that other steps in the same job use can also be reachable, because the runner process holds them in memory. - The checked-out source code and any files the job wrote.
- Build outputs and credentials for cloud providers, such as OIDC tokens or exported keys, when later steps produce them.
- Anything the job can publish, such as packages, releases, or container images.
A step does not need a special privilege to do harm. It runs commands on the runner as the job's user.
A real case
In March 2025 the widely used action tj-actions/changed-files was compromised. An attacker moved many of its version tags to a commit that included code reading secrets out of the runner's memory and printing them to the workflow log. In public repositories those logs are readable by anyone. Workflows that referenced the action by tag picked up the malicious code on their next run, and workflows that referenced a full commit SHA from before the change did not. The incident is tracked as CVE-2025-30066. It also showed that the affected action was itself reached through another compromised action, which previews the transitive-dependency problem covered later in this tutorial.
Why this is a supply-chain risk and not just a bug
Your workflow file may be reviewed carefully, and the repository may require approvals for every change. None of that covers the code at the other end of uses:. The trust boundary sits outside your repository, and you are trusting:
- The people who control the action's repository today.
- Everyone who might control it later, through compromise or transfer.
- Every credential that can write to it.
A branch or tag reference gives you no way to detect a change after the fact beyond reading logs. A pinned commit SHA turns a silent change into an explicit one, because someone has to edit your workflow file to adopt new code.
Common misunderstandings
- "An exact version tag like
v4.2.2is safe." It is less likely to be moved on purpose, but it is still a tag. Nothing stops anyone with write access from pointing it elsewhere. - "The action is from a well-known organization, so it is safe." Larger projects are higher-value targets. Their ref protections are usually better, but a single compromised maintainer account or token is enough.
- "I would notice a bad change in the logs." The malicious step can look like a normal step. Output can be suppressed, or hidden in a way that only an attacker watching the log would spot.
- "Restricting
GITHUB_TOKENpermissions fixes this." It limits damage and is good practice. It does not stop theft of secrets you pass to the job, and the code still runs. - "Dependabot will warn me when a tag moves." Dependabot proposes updates when a newer version appears. It does not report that a tag you already use was repointed to a different commit.
Reducing exposure before you pin
Pinning is the main fix, and the next chapters cover it. Two measures help in any workflow:
name: ci
on: [pull_request]
# Start with no token permissions and grant only what a job needs
permissions: {}
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- run: echo "Pass secrets only to the steps that need them"The restricted token and persist-credentials: false shrink what a hostile step can reach. They do not remove the need to control which code runs.
Summary
- A
uses:reference is resolved by name each time a job starts. The runner has no memory of earlier results. - Branches move with every push. Tags can be moved by deleting and recreating them or by force-pushing them, and floating major tags like
v4are moved on purpose. - A moved ref changes the code in your pipeline with no change in your repository, and that code runs with your job's token, secrets and files.
- Exact version tags, trusted publishers and restricted token permissions each reduce risk. None of them makes the reference immutable.
Exercise
A workflow contains uses: acme/[email protected]. The maintainer's account is compromised, and the attacker force-pushes the tag v2.1.0 to a new commit that prints all environment variables to the log. Your workflow file has not changed. (a) Does the next run use the malicious code? (b) Name two things in that job the code can reach. (c) What single change to the uses: line would have prevented it?
Show answer
(a) Yes. The runner resolves v2.1.0 to a commit at job start, so it fetches whatever the tag points to at that moment, even though the workflow file is unchanged. (b) Any two of: the job's GITHUB_TOKEN, secrets passed to the step through env: or with:, the checked-out source code, and credentials created by earlier steps such as cloud OIDC tokens. (c) Replacing the tag with the full-length commit SHA of the reviewed release, for example acme/deploy-action@<40-character SHA> # v2.1.0, because a SHA identifies exactly one commit and cannot be repointed.