Lockhound
Blog

GitHub settings that stop a repository worm

A stolen token pushed forged commits to 58 of our repositories in 20 minutes. These GitHub settings would have stopped it.

Dec 1, 2026 · 3 min read

A token stolen from one developer's machine was enough for a worm to rewrite the latest commit on 58 of our repositories in about 20 minutes. It kept the original author and date, so the history looked normal.

Every repository it touched was missing the same few settings.

Block force-pushes on your main branches

The worm replaced commits rather than adding new ones, which needs a force-push. A ruleset that blocks force-pushes on main (and any branch you deploy from) stops that on those branches, unless the token's owner is allowed to bypass the ruleset. Branches the ruleset does not cover can still be rewritten.

In your organisation settings, go to Repository → Rulesets and create a branch ruleset for the default branch with:

  • Block force pushes
  • Restrict deletions
  • Require a pull request before merging, with at least one approval. Blocking force-pushes does not stop a stolen token pushing an ordinary new commit straight to main. This rule does. Without a required approval the same token could open a pull request and merge it, so require one from someone other than the last person to push.

An organisation-level ruleset, available on GitHub Team and Enterprise plans, can target all repositories, so it covers new ones too. Without one, the ruleset has to be set on each repository. Either way, set it to Active, and be sparing with its bypass list. Bypass is given to roles, teams and apps, so if repository admins can bypass, a token stolen from any admin walks straight through.

Make the security check required

The same ruleset can make a check mandatory. Add Require status checks to pass before merging and choose Lockhound (GitHub lists it once the check has run on a pull request in that repository). Where GitHub lets you pick the expected source, pick the Lockhound app, so a check with the same name from somewhere else does not count.

From then on a pull request into the default branch can't be merged while its Lockhound check is failing, unless someone allowed to bypass the ruleset overrides it. It fails when the pull request adds a malicious package, a vulnerability known to be exploited, a file that looks like malware, or a new vulnerability at or above the severity you chose. More on pull request checks.

This covers pull requests. It does nothing about a direct force-push, which is why the rule above comes first.

Require signed commits, with a key that needs a tap

Requiring signed commits rejects commits that are not signed and verified. It only helps against malware if the signing key can't be used silently: a hardware key with touch, or an SSH agent that asks before each signature. That makes forging a signature much harder. It does not make a compromised machine safe. A key in a file with no passphrase can be used by malware just as easily as by you.

Use short-lived, narrow tokens

Classic personal access tokens often have repo scope on everything you can reach, and never expire. Prefer fine-grained tokens limited to the repositories they need, with an expiry date. The GitHub CLI's login and SSH keys are not safer by themselves: gh keeps its token in the system's credential store, or in a plain text file when there isn't one, and an SSH key without a passphrase can be copied like any other file. Protect the key with a passphrase or a hardware key.

Watch for the tell-tale signs

The forged commits had a committer that didn't match the author, and a timezone none of us were in. git log -10 --format='%h | %an %aI | %cn %cI' shows author and committer side by side, each with its date and timezone. A mismatch is a reason to look closer, not proof: rebases, cherry-picks and merges made on GitHub produce them too.

Read next