Sub topic 11
Impostor commits and the fork network
This chapter assumes you can read a workflow's uses: lines, know that a commit SHA identifies one commit, and have pinned an action to a full-length SHA as covered earlier. It explains a gap in that technique: a pinned SHA can point to a commit that does not belong to the repository named in the reference.
How a fork can supply a commit
When you fork a repository on GitHub, the fork and its parent share one object store. Git commits pushed to a fork can therefore be fetched through the parent's name. A commit that exists only in a fork, and was never merged upstream, still resolves under the parent's path.
An attacker can use this:
- Fork a popular action.
- Push a commit that adds malicious code to the fork.
- Publish a workflow snippet, a blog post, or a pull request that uses
popular-org/action@<attacker's SHA>.
GitHub resolves that reference successfully, and the workflow runs the attacker's code. A reader sees popular-org/action and assumes the maintainers reviewed the commit. Such a commit is called an impostor commit.
Why a SHA pin does not prevent it
A full-length SHA guarantees that you always get the same commit. It does not guarantee who wrote that commit or that the upstream maintainers accepted it. Pinning fixes the content, so you need to verify the origin separately.
Verifying that a SHA belongs upstream
Take the SHA from the upstream repository's own tag, not from a snippet someone else wrote. The git ls-remote command from the earlier chapter reads tags that the upstream repository actually owns.
You can also check a SHA you did not generate yourself. The GitHub compare API reports how the commit relates to a ref in the upstream repository:
SHA=11bd71901bbe5b1630ceea73d27597364c9af683
gh api "repos/actions/checkout/compare/v4.2.2...$SHA" --jq .statusRead the result as follows:
| Status | Meaning |
|---|---|
| `identical` | The SHA is exactly the commit the tag points to. |
| `behind` | The SHA is an ancestor of the tag, so it is in the upstream history. |
| `ahead` or `diverged` | The SHA is not upstream history. Treat it as suspect. |
Be careful with ahead. A fork commit built on top of a real release shows as ahead, so only accept identical or behind.
Automated detection
You do not have to run these checks by hand for every pin. Static analysis tools for workflows can flag impostor commits. For example, the zizmor linter has an audit for them, and you can run it in CI. Dependabot proposes updates from the upstream repository's releases, so SHAs it writes come from upstream tags, which lowers the risk for pins it manages.
Related caveats
- Deleted forks do not always remove their commits from the network, so a malicious SHA can keep resolving.
- GitHub's SHA-pinning policy checks that a reference is a full-length SHA. It does not check where the commit came from.
- Reviewing a pull request that changes a pin means checking the origin, not only the version comment. A comment such as
# v4.2.2is a note for humans, and nothing verifies it.
Exercise
A blog post tells you to use uses: some-org/build-action@3f1c... (a full 40-character SHA). You run the compare API against the tag v2.1.0 and get the status diverged. What does this suggest, and what should you do?
Show answer
It suggests the commit is not in the upstream tag's history and may exist only in a fork, which makes it a possible impostor commit. Do not use it. Look up the SHA for the release yourself with git ls-remote against the upstream repository, pin that SHA, and confirm the compare status is identical.