From Sidhant Tamrkar | Product & Market Analysis
How the Nx s1ngularity Attack Turned 3 AI Coding CLIs Into Credential Thieves
On this page
On 26 August 2025, an attacker published 8 malicious versions of the Nx build system to npm, and they stayed on the registry for about 4 hours and 12 minutes. The install script searched each developer machine for secrets and then asked any installed AI coding CLI to help. The Nx s1ngularity attack is now the reference case for an AI CLI supply chain attack, and it leaked 2,349 distinct secrets in its first wave alone.
Key takeaways
- The breach started with a pull request title, not a stolen password. A GitHub Actions workflow echoed an unsanitised PR title with write permissions, which let the attacker trigger the publish job and read the npm token.
- The malware ran Claude Code, Gemini CLI and Amazon Q with their safety prompts switched off. It passed the flags that skip permission checks and asked each tool to list sensitive files on the machine.
- The AI step mostly failed. GitGuardian found that of 366 systems where AI tools were targeted, only 95 wrote the requested inventory file, a hit rate of about 26%.
- The real damage came from tokens nobody revoked fast enough. Wiz counted at least 480 compromised accounts that later published over 6,700 private repositories as public.
What happened in the Nx s1ngularity attack
Nx is a monorepo build system that the maintainers say is installed about 6 million times a week. That reach is what made it worth attacking. A package with that footprint sits in the dependency tree of thousands of companies, often several layers below anything an engineer chose on purpose.
The malicious versions carried a postinstall hook, which is a script npm runs automatically after a package is installed. Nobody has to call it. The script ran on Linux and macOS machines, collected environment variables, pulled the GitHub token from the GitHub CLI, and looked for wallets, SSH keys, npm credentials and .env files.
It then created a public repository in the victim's own GitHub account, named with the string s1ngularity-repository, and uploaded the results as a triple base64 encoded file. Exfiltration through the victim's own account is the clever part. No suspicious outbound server was needed, because GitHub traffic from a developer laptop looks normal.
The new twist was step two of the search. The script checked whether Claude Code, Gemini CLI or Amazon Q were installed, and if so it handed them a prompt asking them to inventory sensitive files. That is why security vendors called it the first AI-weaponised supply chain attack, and it is why this post exists.
My position, stated up front: the AI angle is the least important lesson here. It is the most novel, and it should change how your team configures coding agents. But the attack would have worked almost as well without it, and the controls that matter most are the boring ones.
The entry point was a pull request title
The Nx postmortem, published on 5 September 2025, traces the compromise to a workflow that validated pull request titles. It ran on the pull_request_target trigger, which executes with the base repository's permissions rather than the contributor's, and it echoed the title into a shell command without sanitising it.
That gave anyone who could open a pull request the ability to run shell commands inside the Nx repository's CI. According to the GitHub security advisory, the vulnerable workflow arrived in pull request #32458, merged on 21 August 2025, five days before the malicious publish.
Three settings turned an injection into a publish
An injection alone does not publish a package. The postmortem names the conditions that let it escalate. The repository still had workflow permissions set to read and write, a default GitHub changed for new repositories in February 2023 but never applied to existing ones.
The publish workflow also accepted workflow_dispatch, so it could be triggered through the GitHub API by anything holding a suitable token. The attacker's script used the write token to push a branch with a replaced CI script, triggered the publish job, and let that job send the NPM_TOKEN secret out.
It then deleted the branches and workflow runs to cover its tracks. Every one of those steps used a legitimate feature in a way the maintainers had not anticipated.
A long-lived npm publishing token is a bearer credential. Whoever holds it can publish as the project, from any machine, with no further check. Once it left the CI environment, the attacker no longer needed the Nx repository at all.
This is the pattern I would want every engineering lead to absorb. The weak point was not a developer's laptop or a maintainer's password. It was a secret that existed in a place an untrusted input could reach.
The npm package compromise timeline, hour by hour
The clearest timestamps come from StepSecurity and Snyk, which both published UTC timelines on 27 August 2025. The Nx advisory gives removal times in US Eastern time, and they match once converted. Here is the sequence, with phases two and three taken from Wiz's reporting.
How long the packages were live
Sources disagree on the exposure window, and the disagreement is instructive. Snyk and StepSecurity say about 5 hours and 20 minutes, which is the gap between the first publish and the moment the Nx organisation owner revoked the compromised account at 03:52 UTC.
The packages themselves left the registry at 02:44 UTC. That makes the install window 4 hours and 12 minutes by my calculation, close to the 4 hours Nx states in its postmortem. Both numbers are honest. They measure different events, and you should know which one a vendor is quoting.
Which versions to check for
The advisory lists 8 versions of the nx package: 20.9.0, 20.10.0, 20.11.0, 20.12.0, 21.5.0, 21.6.0, 21.7.0 and 21.8.0. It also lists plugin releases of @nx/devkit, @nx/js, @nx/workspace and @nx/node at 21.5.0 and 20.9.0, @nx/eslint at 21.5.0, and @nx/key and @nx/enterprise-cloud at 3.2.0.
The last two stayed up longer. The advisory records their removal at 6:20 AM Eastern, or 10:20 UTC, more than 7 hours after the main package was pulled.
How the AI CLI supply chain attack used coding tools
Snyk published the payload's invocation code on 27 August 2025. The script looked for three command-line tools and called each with the flag that tells it to stop asking for permission.
| Tool | Flag the malware passed | What the flag removes | What to enforce instead |
|---|---|---|---|
| Claude Code | --dangerously-skip-permissions, with -p for a one-shot prompt | The per-action approval prompt for file reads and shell commands | Disable bypass mode centrally where the admin policy supports it, and run it in a container for autonomous work |
| Gemini CLI | --yolo, with -p | Confirmation before each tool call | Keep the default workspace directory restriction, which blocked about a quarter of attempts |
| Amazon Q | chat --trust-all-tools --no-interactive | Per-tool trust decisions and the interactive session | Trust named tools only, never all tools, on a machine with live credentials |
Flags as shown in Snyk's analysis of the payload. The right-hand column is our recommendation, not a vendor statement. The Gemini restriction figure is from Wiz.
What the prompt asked for
The prompt cast the agent as a file-search assistant. It asked the tool to walk the home directory and other local paths, find text and configuration files such as .env files, key files and wallet artefacts. It then had to write the paths to /tmp/inventory.txt without reading the contents.
That last instruction matters. The attacker did not need the model to steal anything. It needed the model to do reconnaissance, a task that looks almost identical to the legitimate work these tools are asked to do every day. The script then read the listed files itself.
Why a coding agent is a useful accomplice
A hard-coded file search has to guess where secrets live. An agent can reason about an unfamiliar directory layout, follow naming conventions, and adapt to whatever the machine contains. It also runs under the developer's own identity, so its file access raises no alarm.
This is the same trust problem covered in the analysis of prompt injection in agent security, arriving from the opposite direction. There the danger is hostile text reaching an agent. Here a hostile process simply calls the agent directly, which no model-side defence was designed to stop.
How often the AI step worked
Not often. Wiz's follow-up report of 3 September 2025 found that about half of victims had at least one AI CLI installed, mostly Claude Code. Almost a quarter of Claude interactions were rejected by the model, and almost a quarter of Gemini runs were stopped by its default workspace restriction.
Wiz concluded that the AI exfiltrated data successfully in under a quarter of cases. GitGuardian's count points the same way: 95 inventory files from 366 targeted systems.
Phase two: developer credential theft at organisation scale
The first wave stole credentials. The second used them. Wiz reported that between about 16:00 UTC on 28 August and 02:00 UTC on 29 August, stolen GitHub tokens were used to rename private repositories and make them public.
By its 3 September count, at least 480 accounts were involved, about two thirds of them organisations, and over 6,700 private repositories had been exposed. One organisation alone had over 700 repositories leaked. A third wave on 31 August published over 500 repositories from a single organisation through two compromised users.
Revocation was the slowest control
Wiz tracked how many leaked GitHub tokens still worked. Almost 90% were valid on the morning of 28 August, more than a day after the leak was public. Almost 80% were still valid on the evening of 29 August. Only after GitHub's own revocation campaign did that fall to roughly 5%.
npm tokens fared worse. Wiz found over 40% of leaked npm tokens from the first phase still valid at the time of its follow-up, almost 100 unique tokens. Each one is a potential publish credential for some other package, which is how one compromise seeds the next.
I think this is the most uncomfortable finding in the whole incident. Developers were told, publicly and loudly, that their tokens had leaked, and most still did not rotate them within a day. Any incident plan that depends on individual engineers acting quickly will fail the same way.
The control checklist, mapped to each step
Every step in the chain had an off-the-shelf control that would have stopped it. The table below pairs them. Rows one to four belong to anyone who publishes packages. Rows five to eleven belong to every team that installs them, which is everyone.
| # | Attack step | Control that breaks it | Owner |
|---|---|---|---|
| 1 | PR title echoed into a shell in a pull_request_target workflow | Never interpolate event fields into run steps; pass them through environment variables. Avoid pull_request_target for untrusted input. | Repository maintainers |
| 2 | Workflow token had read and write permission by default | Set organisation default to read-only and grant permissions per job. | GitHub org admin |
| 3 | Publish job triggered through the API with workflow_dispatch | Run publishing in a protected environment with required human reviewers. | Release owner |
| 4 | Long-lived NPM_TOKEN read from CI secrets | Use npm trusted publishing over OIDC so no reusable token exists. | Release owner |
| 5 | Malicious versions published without provenance | Run npm audit signatures in CI and flag any release that drops provenance. | Platform team |
| 6 | postinstall script ran on every install | Set ignore-scripts by default, allowlist the few packages that need scripts, install with npm ci from a lockfile. | Platform team |
| 7 | AI CLIs called with permission checks skipped | Disable bypass modes in managed configuration; run autonomous agents in containers without home-directory credentials. | Security team |
| 8 | GitHub CLI token, environment variables and .env files harvested | Short-lived, narrowly scoped tokens; secrets in a manager, not in dotfiles or shell environments. | Every developer |
| 9 | Results pushed to a new public repo in the victim's account | Restrict members to private repository creation; alert on new public repositories in the audit log. | GitHub org admin |
| 10 | Stolen tokens flipped private repositories to public | Allow only owners to change repository visibility; automate token revocation on a leak signal. | GitHub org admin |
| 11 | sudo shutdown -h 0 appended to .bashrc and .zshrc | File integrity monitoring on shell startup files through endpoint tooling. | IT |
Steps 1 to 4 are from the Nx postmortem and advisory. Steps 5 to 11 are from Snyk, StepSecurity and Wiz. Controls and owners are our recommendations.
The three rows I would do first
If your team does nothing else, do rows 6, 10 and 2, in that order. Turning off install scripts by default would have neutralised the payload on every machine that installed a bad version. It costs an afternoon of finding the handful of packages that genuinely need a build step.
Restricting visibility changes to owners would have capped phase two at an exposure of credentials rather than of source code. Read-only workflow tokens close the class of bug that started everything. None of the three needs a new vendor.
What Nx changed afterwards
The maintainers' own fixes line up with rows 1 to 5. They moved publishing to npm trusted publishers over OIDC, and now require manual two-factor approval for every publish. They also stopped running pipelines for any outside contributor without approval, and added provenance checks to Nx and Nx Console.
That is a credible response, and it is worth noticing that none of it involved AI. Teams thinking about agent permissions more broadly will find the same logic in the guide to non-human identity for agents, and the scoping question in the OAuth scope review for AI agents.
Where this argument is weakest
There are three places where the case above is thinner than it looks, and you should weigh them before you rewrite policy.
First, the AI framing may be overstated, including by me. The traditional search for environment variables and the GitHub CLI token did most of the damage, and the AI step worked about one time in four. A reasonable reader could conclude that AI coding CLIs made this attack noisier and not much more effective.
The counter, which I find persuasive, is that this was a first attempt. An attacker who tunes the prompt, picks the tool most likely to comply, or waits for models with fewer refusals will do better. Treating a 26% hit rate as reassurance is betting that attackers do not iterate.
Second, the numbers come almost entirely from security vendors. Wiz, GitGuardian, Snyk and StepSecurity all sell products that address parts of this problem. Their counts are drawn from data they could observe, they do not reconcile with each other, and none is audited. GitGuardian's own post reports 1,079 systems in one place and 2,399 repositories in an update.
Third, the control list is written with hindsight. Disabling install scripts breaks some packages, and requiring human approval for every outside contributor slows open source projects that depend on volunteers. These are real costs, and a maintainer with no budget for them is not being careless.
Frequently asked questions
What was the Nx s1ngularity attack?
It was a supply chain compromise in which an attacker published 8 malicious versions of the Nx build system to npm on 26 August 2025, plus several plugin releases. A postinstall script stole environment variables, GitHub tokens, npm credentials and wallet files. It also asked installed AI coding CLIs to locate more secrets, and uploaded everything to a public repository named s1ngularity-repository in the victim's own GitHub account.
How did attackers get the Nx npm token?
A GitHub Actions workflow that validated pull request titles ran on the pull_request_target trigger and echoed the title into a shell. A crafted title ran commands with a read and write repository token. The attacker used that token to swap in a malicious CI script, trigger the publish workflow through the API, and send the NPM_TOKEN secret to an endpoint they controlled.
Which AI coding tools did the Nx malware use?
The payload looked for Claude Code, Gemini CLI and Amazon Q. It ran Claude Code with --dangerously-skip-permissions, Gemini CLI with --yolo and Amazon Q with --trust-all-tools. Each received a prompt asking it to list sensitive files and write the paths to /tmp/inventory.txt. Wiz found the AI step succeeded in under a quarter of cases, often because the model refused.
How do I check if I was affected by the Nx compromise?
Search your lockfiles and npm ls output for the listed nx and @nx versions. Look for a /tmp/inventory.txt file, for repositories with s1ngularity-repository in the name in your GitHub audit log, and for unfamiliar lines in .bashrc or .zshrc. If any match, rotate GitHub, npm and cloud credentials, revoke the GitHub CLI app, and purge the versions from internal registries.
How do you stop npm postinstall scripts from running?
Set ignore-scripts=true in your project or user .npmrc, or pass --ignore-scripts to npm install and npm ci. Then build an allowlist of the few dependencies that genuinely need a build step and run those explicitly. Combine this with lockfile installs through npm ci, so that a new malicious version cannot enter your tree without a reviewed lockfile change.
Is it safe to run AI coding agents with permission prompts disabled?
Not on a machine that holds live credentials. The bypass flags let any process that can call the CLI direct it to read files and run commands without a prompt, which is exactly what the Nx malware did. If your team needs autonomous runs, do them inside a container or remote sandbox that has no access to your home directory, SSH keys or cloud tokens.
Where to start on Monday
Open your organisation's GitHub settings and check two values: the default workflow permission and who may change repository visibility. If the first is read and write or the second includes all members, change them before lunch, because both changes are reversible and cost nothing.
Then ask your platform owner one question: what happens on a developer laptop when a dependency ships a postinstall script tomorrow? If the answer is that it runs, put ignore-scripts on the agenda, and decide where autonomous coding agents are allowed to run. The cost side of that choice is in the comparison of agent sandbox pricing, and the tooling side in the post on MCP server supply chain risk.
Related in this cluster
The same trust failure shows up in agent tooling. Read how MCP servers widen the supply chain and why prompt injection is an architecture problem.
References
- Nx, Juri Strumpflohner, S1ngularity: what happened, how we responded, what we learned, 5 September 2025. Used for root cause, weekly installs, affected versions and remediation.
- Nx maintainers, GitHub security advisory GHSA-cxm3-wv7p-598c, 27 August 2025. Used for versions, removal times, PR #32458 and remediation steps.
- StepSecurity, s1ngularity: popular Nx build system package compromised with data-stealing malware, 27 August 2025. Used for the UTC timeline and provenance note.
- Snyk, Weaponizing AI coding agents for malware in the Nx malicious package, 27 August 2025. Used for AI CLI flags, prompt content and payload behaviour.
- Wiz, s1ngularity: supply chain attack leaks secrets on GitHub, 27 August 2025, updated to 29 August. Used for phase two timing.
- Wiz, Rami McCarthy, s1ngularity's aftermath: AI, TTPs, and impact, 3 September 2025. Used for AI CLI success rates, phase two and three counts and token validity.
- GitGuardian, The Nx s1ngularity attack: inside the credential leak, 27 August 2025, updated to 29 August. Used for secret counts and the 366 versus 95 figure.
Weakest point in the source base: every victim count comes from security vendors observing the leaked repositories they could see. The counts are unaudited and do not reconcile with each other. Figures last verified 27 November 2026.
Related reading