One Tuesday morning I went to push to one of a client’s repositories and Git refused: the remote had work I didn’t have, pull and rebase first. That happens on a team every day. I rebased, pushed, and carried on.
That afternoon the client sent round an incident report about malicious force-pushes to the organisation. The commit I had rebased onto was one of them. By then my Mac had been running it since breakfast.
What the payload looked like
Every infected branch had had its last commit rewritten in place. Same author, same date, same message, so git log looked exactly as it did yesterday. The changes were small and placed where nobody reads:
- A new
api.jsat the repository root: about 28 KB of obfuscated JavaScript on a single line. node api.js &&prepended to scripts inpackage.json, sonpm start,npm testornpm run devran it first.- The same loader appended to config files that tools execute without anyone opening them:
eslint.config.js,postcss.config.js,tailwind.config.js,babel.config.js,metro.config.js. It sat after a long run of whitespace on the last line, so in an editor the file ends where it always did and the code is off to the right, past the edge of the screen. - New
.gitignoreentries hiding the files it drops, such astemp_auto_push.bat.
The config-file trick is the clever part. You do not have to run the app to get infected. Your editor’s ESLint integration loads eslint.config.js to lint the file you have open. Metro loads its config when Expo starts. Opening the project is enough.
On my machine it had started a Node backdoor and a Python credential stealer, and it had dumped the project’s environment files into hidden folders under /tmp. It found its command server by reading from public Ethereum RPC endpoints, which is why a firewall showing node talking to eth.drpc.org or 1rpc.io is the thing to watch for. The indicators matched a campaign security researchers track as PolinRider, which spreads from developer to developer through exactly this kind of shared repository.
Day one: the machine, then the repositories
On the Mac: kill the 20 processes it had started, delete what it had dropped, then delete every node_modules, .expo and .next under my projects folder so nothing cached could re-run it. Unpushed work went out as git format-patch files and bundles, which are plain text and binary history that I could read before trusting, and then the checkouts were deleted.
On GitHub, the client made me an owner of the organisation so I could clean it. The first wave had hit 88 branches in 28 repositories, and a second wave from another contributor’s infected machine hit 39 more. I never cloned an infected branch to fix it. Cloning means checking out, and checking out means an editor or a hook might load a config file. Everything went through the API instead.
GitHub’s repository activity endpoint records every push with the ref, the actor, and the SHA before and after, including force-pushes, which git log cannot show you because the old commit is no longer in the branch:
gh api "repos/OWNER/REPO/activity?activity_type=force_push&per_page=100" \
--jq '.[] | [.timestamp, .actor.login, .ref, .before, .after] | @tsv'For each branch, before is the last clean commit. If nobody had pushed real work on top of the attack, resetting the branch to before was the fix: 78 branches. On 13, teammates had already pushed legitimate commits on top of the infected one, so I rebuilt those through the git data API: start from the clean commit, re-apply only the real changes, never the payload files. 91 branches restored that day.
Day two: what I missed
I’d fixed the machine and the client’s organisation. The worm had two more ways back in.
The first was a credential I hadn’t revoked yet. Just after midnight UTC, something holding a valid token for my GitHub account force-pushed the payload into 59 branches across 24 of my own repositories and two other clients’ organisations, in six minutes. Same technique, rewritten tip commits, pushed as me. GitHub’s security log showed no new login or token creation around that time, so it was something the stealer had taken on day one. Rotating from a clean device was on my list, and the attacker got there first.
That morning I revoked everything: every OAuth app including the GitHub CLI and the mobile app, every GitHub App installation, every SSH key and every session but the one I was using. Then the same activity-API restore across all 24 repositories. One teammate had pushed real work on top of an infected commit seconds after the attack, so that branch was rebuilt to keep their commit and drop the payload. A rescan of 132 branches in 27 repositories came back clean.
The second was the first cleanup itself. A second pass over the client’s organisation found 12 repositories where day one’s restore had missed payload in config files. Fixing those meant 39 new commits, but one of those repositories ran its test suite in GitHub Actions on push, and its package.json was one of the infected ones. The worm had already run once in CI, with the CI secrets in its environment. Before pushing the fixes I disabled the affected workflows and the deploy webhooks so that the cleanup push itself couldn’t trigger a build, pushed all 39 as plain fast-forwards, and left deploys paused until they could be redone by hand from clean commits.
The thing a new user account doesn’t fix
Instead of reinstalling macOS, I created a new user account, copied plain files across, and left the old user’s dotfiles, caches and tool installs behind. The first check of the new account found npm infected.
Homebrew installs into /usr/local, which every user on the Mac shares. The worm had appended its loader to the end of npm’s own lib/cli.js, so every npm command, run by any user, started it. A clean home folder doesn’t help when the infected program is outside it. I removed Homebrew’s Node and npm entirely and moved to nvm, which keeps Node inside the user’s home.
# Is your global npm carrying anything after its own code?
grep -c "global\[" "$(dirname "$(readlink -f "$(command -v npm)")")/../lib/cli.js"
# Any repo: a root api.js, a loader in package.json scripts,
# or a config file with a suspiciously long line
test -f api.js && echo "root api.js present"
grep -n "node api.js" package.json
git ls-files | grep -E '(^|/)(eslint|postcss|tailwind|babel|metro|jest|vite)\.config\.[cm]?[jt]s$' |
while read -r f; do awk -v f="$f" 'length > 1000 { print f ": line " NR " is " length " chars" }' "$f"; donenpm’s cli.js is about a dozen lines long and has no reason to mention global[; a count above zero is worth looking at. None of these checks run project code, which matters, because the obvious way to check a JavaScript project is to run its tooling, and the tooling is what’s infected.
Keeping watch
Cleaning up once isn’t enough when other people’s machines can still push. I wrote a small shell tool that keeps bare mirrors of all 166 repositories I can push to across my account and the client organisations, and on a schedule:
- flags any force-push since the last run, with who did it;
- flags changes to CI workflow files;
- scans every branch tip for the payload markers, without checking anything out;
- and has an
incomingmode I use instead ofgit pull: fetch only, then list the incoming commits and files, warn on rewritten history, new sensitive files, or any added line over 1,000 characters. I merge by hand after reading it.
Its first full run audited every force-push in the attack window and found one the scans had missed: my GitHub profile README repository, where the only change was the attacker’s .gitignore. That was restored too. 418 branch tips clean.
What I’d tell another developer
- “Pull and rebase first” on a branch only you push to is an alarm. Fetch and look at what changed before you merge anything.
- Revoke first, clean second. I cleaned the repositories and the machine before rotating the credentials, and a stolen token undid a day’s work in six minutes. Tokens, SSH keys, OAuth apps and sessions go before anything else.
- Config files are code.
eslint.config.jsruns when your editor opens the project. Review them like source, and be suspicious of any line that runs past the right edge of the screen. - Pause CI and deploys before pushing a fix. Your fix is a push, and a push runs the pipeline on whatever is in the branch.
- Clean up through the API. The activity log has the before and after of every force-push, and the git data API can rebuild a branch without the infected code ever touching a disk.
- Protect your branches. Blocking force-pushes on main and release branches would have turned every one of these attacks into a rejected push.
Donald Amoke builds and ships mobile apps. See the work or read more notes.