DEV Community

Cover image for The npm Worm That Learned to Trust Your AI Agent
Cor E
Cor E

Posted on

The npm Worm That Learned to Trust Your AI Agent

Your editor's autopilot is now part of your attack surface

Here's the part that should stop you mid-scroll: this isn't just another npm worm harvesting .env files. It's a worm that plants hooks in Claude Code and VS Code, waiting for the moment you trust a workspace, so it can execute without you doing anything else stupid. That's a new kind of trigger, and it deserves more than zero comments.

We've seen this movie before, mostly

Credential-stealing npm worms are not new. Preinstall/postinstall script abuse has been the go-to vector for years, event-stream, ua-parser-js, the colors/faker sabotage, take your pick. Keyv itself is a small, widely-depended-on caching library, exactly the kind of low-glamour package that makes a perfect worm vector because nobody's watching it closely. Popular enough to spread, boring enough to ignore. That part of the story is depressingly familiar.

What's different is the payload's choice of home. Instead of just exfiltrating secrets and calling it a day, whoever built this planted SessionStart and folderOpen hooks tied to AI coding agents and editor tooling. That's not lateral movement through infrastructure. That's lateral movement through developer habit. You open a folder, your agent starts a session, and the trust boundary you thought you had (workspace trust prompts, sandboxing assumptions) gets used against you as the actual detonator.

The hype and the quiet part nobody's saying loudly enough

The "AI coding agents are now a supply chain attack surface" framing will get milked hard in the next few weeks, and honestly, it's earned this time. But let's be precise about what's overstated and what's underappreciated.

Overstated: that this is some sophisticated AI-specific exploit. It's not. Claude Code and VS Code hooks are just automation surfaces, config-driven task runners that happen to fire on predictable lifecycle events. The attacker didn't break AI security, they found a lifecycle hook with a broad enough trigger condition (opening a folder, starting a session) and abused it exactly like npm scripts have been abused for a decade. Same playbook, new floor.

Understated: how much of the industry has quietly decided that "trusting a workspace" is a one-time, low-friction decision. Workspace trust prompts exist because editors learned, painfully, that arbitrary code execution on folder-open is dangerous. Adding agent tooling with its own hook system on top of that trust model just recreates the same problem at a new layer, and most people clicking "trust this workspace" have no mental model of what that trust now actually grants.

Who benefits from the loud version of this story? Frankly, everyone selling "AI security" tooling right now has a strong incentive to make this sound like a novel AI threat rather than a supply-chain problem that happened to touch AI tooling. The real lesson is boring: transitive dependencies plus automatic script execution plus broad trust grants equals bad outcomes, whether the trigger is npm install or an agent's SessionStart hook.

What this actually means for people shipping code

If you're pulling keyv or anything downstream of it, you're auditing dependency trees today, not next sprint. But the bigger structural takeaway is that agent and editor hook systems need the same scrutiny CI pipelines got after the last five years of npm worms. Nobody threat-modeled "what happens when a hostile package plants a hook that fires when Claude Code starts a session." That's an obvious gap in retrospect, the kind that's always obvious in retrospect.

For security teams, this is a good moment to actually go look at what hooks your AI coding tools support, and what triggers them. Not hypothetically. Open the docs. Most teams have zero visibility into this because it's new enough that it hasn't made it into anyone's asset inventory or policy yet.

For the ecosystem, preinstall/postinstall script restrictions have been debated forever and mostly ignored because they're inconvenient. Every time one of these worms hits, someone proposes disabling lifecycle scripts by default. Every time, it doesn't stick because too much tooling depends on it. I don't expect that calculus to change this time either, even with AI agents now in the blast radius.

The question worth sitting with

If workspace trust and dependency trust are both single, coarse-grained decisions, and agent tooling keeps adding new automatic triggers on top of that trust, at what point does "trusting a workspace" stop meaning anything specific at all?

— Cor, Skyblue Soft

Sources

Top comments (0)