Repository navigation
Documentation as attack surface: npm libraries teaching insecure patterns in README examples #1560
Description
Activity
Update: 5th library review adds crypto-js (15.6M weekly downloads)
Filed brix/crypto-js#534 — the README's AES encryption examples derive keys using EVP_BytesToKey with MD5 and 1 iteration. A GPU can test billions of candidate passphrases per second. Default cipher mode is CBC without authentication (padding oracle vulnerable).
The pattern count is now 5 libraries, ~195M weekly downloads:
Library Downloads/week CWE Issue crypto-js 15.6M CWE-328 (Weak Hash), CWE-916 (Insufficient KDF) #534 axios 65M CWE-319 (Cleartext Transmission) GHSA-8wrj-g34g-4865 node-jsonwebtoken 76M CWE-185 (Incorrect Regex) #1019 cors 25M CWE-185 (Incorrect Regex) #408 multer 13.5M CWE-330 (Insufficient Randomness) #1386 The crypto-js finding is notable because the library is discontinued — these insecure examples will remain permanently in the README of the most-downloaded encryption library in the npm ecosystem. Updated analysis: The Documentation Attack Surface.
Update: axios supply chain compromise validates documentation attack surface pattern
The axios supply chain compromise on March 31, 2026 was caught and remediated within 3 hours. But the documentation security issues I filed on the same library weeks earlier (axios#10614, GHSA-8wrj-g34g-4865) remain open.
This is the pattern in action: the ecosystem has excellent tooling to detect supply chain attacks (the malicious versions were flagged within minutes), but zero tooling to detect insecure patterns taught by documentation. Teams are now auditing their lockfiles for
axios@1.14.1— but nobody is auditing code they copied from axios README examples.I posted a comment on the post-mortem suggesting teams add documentation pattern review to their incident response checklist.
The portfolio now covers 5 libraries across ~195M weekly downloads. Updated analysis: Your Dependencies Have Two Attack Surfaces.
Good research. This is likely to become even worse now that the usage of AI for code generation is more widespread - popular AI models have a bad habit of producing examples with subtle security issues, and AI-written code often doesn't go through a proper review process.
@Neustradamus I thought crypto-js was deprecated because there's now native libraries to do crypto? Why is a new package needed?
@Daniel15: Badly, several projects use always this unsecure crypto-js library...
What is the other solutions than crypto-es?
@Neustradamus Web Crypto API works in both Node.js and in browsers. https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API and https://nodejs.org/api/webcrypto.html
Node.js also has its older crypto API https://nodejs.org/api/crypto.html
Reacted by Neustradamus@Daniel15: Thanks for your details! :)
All users do not use Node.js :/
Proposed a maintainer-facing README security checklist under processes/: #1579 — defensive/docs-only, aligned with the guidance ideas in this issue.
Summary
Across 4 reviews of high-profile npm libraries — totaling ~180 million weekly downloads — I found the same pattern: the library code handles security correctly, but the README teaches developers to copy insecure patterns.
One finding resulted in a GitHub Security Advisory (GHSA-8wrj-g34g-4865) filed at the maintainer's request.
This isn't a bug in any single library. It's a systemic issue in how the npm ecosystem documents security-sensitive operations.
Findings
1. axios —
beforeRedirectbypasses credential-stripping (65M weekly downloads)The README example re-injects credentials via
beforeRedirectafterfollow-redirectsdeliberately strips them on protocol downgrades (HTTPS→HTTP). The callback fires after the security mechanism (follow-redirects line 478), directly bypassing it.2. node-jsonwebtoken — Unanchored regex audience matching (76M weekly downloads)
Documentation allows
jwt.verify(token, key, { audience: /api\.myapp\.com/ })without^/$anchors. An attacker can bypass withaud: "evil-api.myapp.com.attacker.com".3. cors — Unanchored regex origin validation (25M weekly downloads)
README example
/example\.com$/matchesevil-example.com. Combined withcredentials: true, allows authenticated CORS access from attacker-controlled domains. The library's own test suite uses the correct pattern.4. multer —
Math.random()for filenames (13.5M weekly downloads)README's
diskStorageexample usesMath.random()(~30 bits entropy) while the library's default usescrypto.randomBytes(16)(128 bits). If uploads are web-accessible, filenames can be enumerated.The Pattern
Three forces create this systematically:
Math.random(), that's what gets deployed.Potential Actions for the WG
src/changes.eslint-plugin-securityflagsMath.random()in source, flag it in docs too).Methodology
Each library was reviewed by examining README code examples against the library's actual implementation, looking for cases where the documentation teaches a weaker pattern than what the library provides by default. Findings were verified by reading the library source code.
Full review reports and meta-pattern analysis: gist