Sub topic 11
Impostor commits and the fork network
This chapter assumes you can read a GitHub Actions workflow and you know that a full-length commit SHA is a 40-character hex identifier for one commit. It also assumes you have seen how git ls-remote lists tags. It builds on the earlier chapters on pinning and on resolving the SHA behind a tag.
SHA pinning is only as trustworthy as the SHA you pin. A 40-character value can look correct and still point at code the action's maintainers never published. This chapter explains how that happens, how to detect it, and what it means for your review process.
How GitHub stores forks
When you fork a repository on GitHub, the fork does not get a fully separate copy of the Git objects. The original repository, its forks, and forks of those forks form a fork network. GitHub stores the objects for the whole network together, so it does not duplicate every commit for every fork.
One consequence is that a commit is addressable by its SHA through any repository in the network. Suppose someone forks actions/checkout and pushes a commit to the fork. That commit can then be fetched using the URL of the upstream repository, as long as you give its full SHA. The commit does not appear in any upstream branch, tag, or history. The upstream URL can still serve it.
The Actions runner resolves uses: owner/repo@<sha> by asking GitHub for that commit in that repository. It does not check that the commit is reachable from a branch or tag of that repository. A SHA that exists only in a fork therefore resolves normally and the job runs the fork's code.
What an impostor commit is
An impostor commit is a commit that you reach through a trusted repository's name, but that does not belong to that repository's own branches or tags. It lives in a fork, or in an unmerged pull request, and the shared object store makes it available.
The attack needs these steps:
- The attacker forks a popular action.
- The attacker pushes a commit containing malicious code to the fork.
- The attacker gets a victim to adopt a reference like
uses: actions/checkout@<malicious-sha> # v4.2.2.
Step 3 is the hard part, and it usually takes the form of a pull request that looks routine. The next example shows such a change.
steps:
# Before: a legitimate pin
# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# After: a "routine dependency bump" that swaps in a fork-only commit
- uses: actions/checkout@0123456789abcdef0123456789abcdef01234567 # v4.2.2The SHA is full-length, the repository name is correct, and the comment claims the same version. The pull request diff gives a reviewer no visual signal. The version comment is free text, and nothing checks it against the SHA.
Why this is not just a theoretical risk
Three properties make impostor commits practical:
- Pins look authoritative. Teams learn that SHA pinning is the safe choice. A SHA-pinned reference therefore gets less scrutiny than a tag.
- The version comment is unverified. Reviewers read the comment, not the hash.
- Tooling may not catch it. Dependabot proposes updates from legitimate releases, but it does not audit a SHA that a human typed into a pull request.
The attack does not require write access to the upstream repository. That is why it differs from the tag-repointing risk in earlier chapters. There, an attacker needs write access, or compromises someone who has it. Here, anyone who can open a fork can create the commit, and only the review step stands in the way.
Verifying that a SHA belongs to the upstream repository
The check is always the same: confirm that the commit is reachable from a ref that the upstream repository owns. There are three practical ways to do it.
Compare against the tag the SHA claims to be
git ls-remote against the upstream URL lists only the refs that upstream owns. Fork refs do not appear. If the tag's resolved commit equals your pin, the pin is legitimate. This is the same command from the resolving chapter:
git ls-remote https://github.com/actions/checkout 'refs/tags/v4.2.2' 'refs/tags/v4.2.2^{}'With an annotated tag, use the ^{} line, because the first line is the tag object and not the commit.
Ask the compare API
A pin does not always sit on a tag tip. You may pin a commit between releases. The GitHub compare endpoint works across the fork network, so you can ask whether your SHA is an ancestor of a known upstream ref. The status field reports behind when the head commit is an ancestor of the base. It reports identical when they are the same.
#!/usr/bin/env bash
# usage: verify-pin.sh OWNER/REPO FULL_SHA TAG
set -euo pipefail
repo="$1"; sha="$2"; tag="$3"
tag_sha=$(git ls-remote "https://github.com/${repo}.git" \
"refs/tags/${tag}" "refs/tags/${tag}^{}" | tail -n 1 | cut -f1)
if [ "$tag_sha" = "$sha" ]; then
echo "OK: ${tag} in ${repo} resolves to ${sha}"
exit 0
fi
status=$(gh api "repos/${repo}/compare/${tag}...${sha}" --jq .status) || status="error"
echo "Tag ${tag} resolves to ${tag_sha:-<none>}; compare status: ${status}"
if [ "$status" = "behind" ]; then
echo "OK: ${sha} is an ancestor of ${tag}, so it is part of upstream history"
exit 0
fi
echo "FAIL: ${sha} is not proven to be part of ${repo}'s history. Inspect it manually." >&2
exit 1The script treats behind as the only passing result for a non-tip commit. A status of ahead or diverged means the commit is not an ancestor of the tag. It might be a legitimate later commit on the default branch. It might also be a fork commit built on top of the tag. The script cannot tell the two apart, so it fails and asks for a manual look.
Look in the web interface
When you open a commit URL under the upstream repository and the commit is not on any upstream branch, GitHub shows a banner saying the commit does not belong to any branch on this repository and may belong to a fork. Use this for manual spot checks. Do not rely on it as a control, because it works only if someone looks.
Clone and ask Git
A normal git clone of the upstream repository fetches its branches and tags, not fork refs. After cloning, run git cat-file -t <sha>. If the commit is missing, the SHA is not on any upstream branch or tag. If it is present, git branch -r --contains <sha> and git tag --contains <sha> show which refs reach it. Unmerged pull request commits live under refs/pull/ upstream, so they are also absent from a default clone.
Automating the check
Running a script by hand for every pin does not scale. Static analysis tools for workflows can run the same reachability check across a repository. The tool zizmor includes an audit named impostor-commit. It needs a GitHub token to query the API.
GH_TOKEN="$(gh auth token)" zizmor .github/workflows/Run such a tool in CI on every pull request that touches .github/. That puts the reachability check at the point where a malicious swap would arrive. Pair it with a rule in your review process: a change to a pinned SHA needs a link to the upstream release or the output of a verification step.
Limits of the check
Reachability from an upstream branch or tag shows the commit belongs to the upstream repository's history. It does not show the commit is safe. These cases remain:
- Compromised upstream. If an attacker pushes a malicious commit to an upstream branch, the commit is reachable and passes the check. Pinning protects you from later changes. It does not protect you from the first bad commit you adopt.
- Reachable but unreleased commits. A commit on a development branch has not been through the maintainer's release process. Prefer SHAs that match release tags.
- Changing network state. Whether a deleted fork's commits remain fetchable depends on GitHub's storage and cleanup behavior. Do not assume a commit disappears when its fork does. Re-verify pins you did not create yourself.
Summary table
| Question | Check | Conclusive result |
|---|---|---|
| Is the pin the tip of the claimed release? | `git ls-remote` against the upstream URL | Resolved commit equals the pinned SHA |
| Is the pin an older commit in a release's history? | Compare API, tag as base and SHA as head | `behind` or `identical` |
| Is the pin on any upstream ref? | Clone upstream, then `git branch -r --contains` and `git tag --contains` | At least one upstream ref contains it |
| Is the pin in a fork or pull request only? | `git cat-file -t` fails in a default clone | Commit is missing from the clone |
Practical rules
- Generate pins with tooling that resolves them from upstream tags, rather than pasting SHAs from search results, blog posts, or issue comments.
- Run a reachability check in CI on any pull request that changes a
uses:line. - Require a reviewer to confirm the SHA against the upstream release page for each new or changed pin.
- Prefer SHAs that match release tags, so the
git ls-remotecheck is enough. - Keep Dependabot enabled so legitimate updates arrive from the tool and not from hand-edited hashes.
Exercise
A pull request changes uses: acme/deploy@<sha-A> # v2.1.0 to uses: acme/deploy@<sha-B> # v2.1.1. The diff is only these lines. git ls-remote https://github.com/acme/deploy 'refs/tags/v2.1.1' 'refs/tags/v2.1.1^{}' prints a tag object line, and a second line whose commit is <sha-C>. <sha-B> is not equal to <sha-C>. What does this suggest, which value should the workflow use if the release is genuine, and why does the version comment not settle the question?
Show answer
The mismatch suggests <sha-B> may be an impostor commit, for example one that exists only in a fork or an unmerged pull request and is served through the shared fork network. For an annotated tag, the second line (^{}) holds the commit the tag resolves to, so a genuine v2.1.1 pin should use <sha-C>. The comment # v2.1.1 is free text that no tool checks against the SHA, so an attacker can write any version there. Before merging, confirm the commit through the compare API or a clone of the upstream repository, and check the upstream release page.
Exercise
Your verification script calls the compare API with the tag v3.0.0 as the base and your pinned SHA as the head, and the status is ahead. Why should the script not treat this as a pass?
Show answer
ahead means the pinned commit is a descendant of the tag, not an ancestor. It could be a legitimate later commit on the upstream default branch. It could equally be a commit in a fork that was built on top of the tag. The API result alone cannot distinguish the two, so a person must inspect the commit or confirm it against an upstream branch.