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 and know what a Git tag, branch, and commit are. It explains why the common uses: owner/repo@v4 form is a moving target, and what an attacker can do with that.
What a reference resolves to
Every uses: entry has the form owner/repo@ref. The ref can be a tag, a branch, or a commit SHA. When a job starts, the runner downloads the action's code at that ref and runs it. It does this on every run, not once.
| Ref type | Example | Can it move? |
|---|---|---|
| Branch | `@main` | Yes. Each push moves it. |
| Tag | `@v4` | Yes. Anyone with write access can delete it and recreate it elsewhere. |
| Full commit SHA | `@11bd7190...` | No. It names one commit. |
A tag is only a pointer to a commit. Nothing in Git makes that pointer permanent. Major-version tags such as v4 are moved on purpose by maintainers, so that users get fixes automatically. The same mechanism works for anyone else who gains write access.
How a retagged action reaches your pipeline
An action runs inside your job. It can read the job's environment, and it receives the GITHUB_TOKEN and any secrets you pass to that step. Some actions also run in jobs that deploy to production. If an attacker can change the code behind a ref you use, they can run code with those same privileges.
The attack needs no change in your repository. The sequence looks like this:
The attacker could be a compromised maintainer account, a stolen token, or a contributor with write access. The workflow file in your repository is unchanged, so a code review of your own repository shows nothing unusual.
A real pattern
Attacks of this kind have happened in public. In March 2025, the widely used tj-actions/changed-files action was compromised. The attacker repointed many existing version tags to a commit that printed secrets from runner memory into the workflow logs. Repositories that referenced the action by tag ran the malicious code on their next run. Repositories that referenced a full commit SHA from before the change did not.
Seeing the risk in your own workflow
Compare these two references. The first follows a tag. The second names one commit, with the version in a comment for humans.
steps:
# Mutable: the tag can be moved to a different commit
- uses: actions/checkout@v4
# Immutable: a full-length commit SHA identifies exactly one commit
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2With the first form, two runs of the same workflow file a week apart can execute different code. With the second, they cannot. Pinning is covered in the next chapter.
Common misconceptions
- "Official actions are safe." Publisher reputation lowers the chance of a problem but does not change the mechanism. A tag in an official repository is just as movable.
- "A semantic version tag is fixed."
v4.2.2looks like a release, but Git treats it like any other tag. Some repositories protect release tags, but you cannot assume it. - "I read the action's code once." Your review applies to the commit you read. A tag reference does not guarantee you will get that commit later.
- "The log will show it." The log shows the tag you asked for, not the commit it resolved to on that day, unless you check the "Set up job" section carefully.
What reduces the exposure
Pinning removes the moving pointer. Two other measures limit the damage if a bad commit does run:
- Set the narrowest
permissions:for the workflow token. - Pass secrets only to the steps that need them.
These help but do not replace pinning, because the malicious code still runs.
Exercise
A workflow uses uses: some-org/deploy-action@v2. Last week it behaved normally. Today the maintainer's account was compromised and v2 was moved to a new commit. Without any change to your repository, what happens on your next run, and which reference form would have prevented it?
Show answer
The runner resolves v2 to the attacker's new commit and runs it with the job's token and secrets, even though your workflow file is unchanged. Referencing the action by the full-length commit SHA of the version you reviewed would have prevented it, because a SHA names exactly one commit and cannot be repointed.