# Nx (s1ngularity): a PR title injection stole an npm token and weaponized local AI CLIs

- **Canonical URL:** https://breachidents.com/incidents/nx-aug-2025-s1ngularity-npm-attack
- **Organization:** Nx
- **Incident date:** Aug 26, 2025
- **Disclosed / updated:** Sep 5, 2025
- **Category:** CI supply chain
- **Primary source:** Nx Official Postmortem and GHSA-cxm3-wv7p-598c (https://nx.dev/blog/s1ngularity-postmortem)

## In 30 seconds

- **How they got in:** Unsanitized PR title echoing in a pull_request_target workflow ran shell commands with a read/write GITHUB_TOKEN _[Confirmed]_
- **What leaked / reached:** nx (20.9.0–20.12.0, 21.5.0–21.8.0) and companion @nx/* npm packages; developer SSH keys, tokens, and .env files pushed to public s1ngularity-repository GitHub repos
- **What stayed safe:** Nx Cloud production platform, Nx Enterprise infrastructure, and the official CI release pipeline itself (tampered builds lacked npm provenance)

## Summary

On August 26, 2025, attackers chained three GitHub Actions settings inside the Nx monorepo project (pull_request_target, legacy read/write token defaults, and workflow_dispatch on publish.yml) to steal Nx’s npm publishing token. For four hours, tampered releases across eight nx versions and seven companion packages ran a postinstall script that invoked local AI CLI tools (Claude, Gemini, Amazon Q) to scan developer disks and upload secrets to public s1ngularity-repository repos. Nx Cloud was unaffected.

## Attack sequence

1. **Aug 26, 2025 — Shell commands in a PR title execute under pull_request_target with write token:** A malicious PR title triggers command injection in Nx’s PR-title validation job, exposing a legacy read/write GITHUB_TOKEN.
2. **Aug 26, 2025 — Attacker pushes a rogue branch, dispatches publish.yml, and publishes to npm:** Using workflow_dispatch on publish.yml, the attacker steals NPM_TOKEN, wipes the branch and workflow run, and publishes tampered nx and @nx/* packages lacking provenance.
3. **Aug 26, 2025 (4 hours) — Postinstall abuses local AI CLIs and leaks secrets to s1ngularity-repository repos:** Infected developer machines run telemetry.js, abuse local AI CLIs to inventory sensitive files, publish base64 dumps to public GitHub repos, and sabotage shell startup files until npm pulls all bad versions four hours later.

## How they got in

Nx's September 5, 2025 postmortem is a textbook illustration of how three individually mundane GitHub settings turn into full registry compromise.

First, a PR-title validation workflow ran on `pull_request_target` (which executes with target-branch permissions and secrets) and echoed the untrusted PR title directly into a shell command. Second, because the repository pre-dated February 2023, it still carried GitHub's old default setting of "Read and write permissions" for Actions tokens. Third, `publish.yml` had `workflow_dispatch` enabled so maintainers could trigger manual runs.

Chaining those three together took minutes. The attacker opened a PR with shell commands in its title, used the read/write `GITHUB_TOKEN` to push a temporary branch swapping a CI script, triggered `publish.yml` against that branch through the GitHub API to steal `NPM_TOKEN`, and deleted the branch and workflow run to clean up.

## What it reached

With `NPM_TOKEN` in hand, the attacker bypassed Nx's CI completely and pushed tampered releases directly to npm across `nx` (`20.9.0`–`20.12.0`, `21.5.0`–`21.8.0`), `@nx/devkit`, `@nx/js`, `@nx/workspace`, `@nx/node` (`20.9.0`, `21.5.0`), `@nx/eslint` (`21.5.0`), and `@nx/key` and `@nx/enterprise-cloud` (`3.2.0`).

The postinstall payload (`telemetry.js`) introduced a twist security teams had never seen at scale: it hunted for local AI coding CLIs (Claude Code, Gemini CLI, Amazon Q) and invoked them with permission-bypassing flags to recursively locate credentials, keys, and tokens across the filesystem. Harvested secrets were encoded into `results.b64` and uploaded using the developer's own GitHub CLI to newly created public repositories named `s1ngularity-repository*`, while some variants appended `sudo shutdown -h 0` to `~/.bashrc` and `~/.zshrc`.

## What stayed safe

Because the rogue packages lacked npm provenance signing, Nx immediately knew its official CI release pipeline had not built them. Within four hours, npm pulled every tampered package and revoked all Nx tokens, while GitHub took down leaked repositories. Nx Cloud was architecturally isolated from open-source npm publishing and stayed completely untouched.

## How to defend against this

- **Default read-only token** (Stops step 1): Set repository Actions workflow permissions to read-only by default, avoid pull_request_target on untrusted PR metadata, and pass titles through env vars instead of inline shell interpolation.
- **OIDC Trusted Publisher** (Stops step 2): Delete static NPM_TOKEN secrets, enable npm Trusted Publishers with OIDC, and require manual environment approval with 2FA before any release publishes.
- **Block install scripts** (Catches step 3): Disable npm lifecycle scripts by default (ignore-scripts=true) and alert on unexpected public GitHub repo creations or shell profile edits (sudo shutdown -h 0).

## Evidence log

| Section | Claim | Evidence state | Source |
| --- | --- | --- | --- |
| How they got in | Three conditions aligned: pull_request_target with unsanitized PR title echoing, legacy read/write Actions default permissions, and workflow_dispatch enabled on publish.yml | Confirmed | Nx Official Postmortem, Sep 5, 2025 |
| What it reached | Tampered versions included nx 20.9.0–20.12.0 and 21.5.0–21.8.0, @nx/devkit, @nx/js, @nx/workspace, @nx/node (20.9.0, 21.5.0), @nx/eslint (21.5.0), and @nx/key and @nx/enterprise-cloud (3.2.0) | Confirmed | Nx Official Postmortem and GHSA-cxm3-wv7p-598c |
| What it reached | Postinstall payloads abused local AI CLI tools (such as Claude and Gemini), pushed secrets as results.b64 into public s1ngularity-repository GitHub repos, and appended sudo shutdown -h 0 to ~/.bashrc and ~/.zshrc | Confirmed | Nx Official Postmortem and GHSA-cxm3-wv7p-598c |
| What held | Nx Cloud was never affected and remained fully operational and isolated from OSS npm releases | Confirmed | Nx Official Postmortem, Sep 5, 2025 |

## Indicators of compromise

- **Repository:** `s1ngularity-repository* (results.b64)` (undefined)
- **File:** `/tmp/inventory.txt` (undefined)
- **Command:** `sudo shutdown -h 0 in ~/.bashrc or ~/.zshrc` (undefined)

---
Published by [breachidents](https://breachidents.com). Preserve evidence labels (Confirmed / Inferred / Withheld by vendor / Observed) when citing.
