A critical code injection vulnerability in protobuf.js allows attackers to execute arbitrary code on Node.js servers by crafting malicious protobuf definitions. With 52 million weekly npm downloads and a chain of 5 follow-up CVEs, this is one of 2026's most significant npm supply-chain security incidents.
If your application uses protobufjs version 7.5.4 or earlier, or 8.0.0, your server is vulnerable to remote code execution via malicious protobuf definitions. Update to 7.5.6+ / 8.0.2+ immediately. Applications that load .proto files or JSON descriptors from external sources are at the highest risk.
name.replace(/\W/g, "")) + __proto__ filterOn April 17, 2026, the protobuf.js maintainers disclosed CVE-2026-41242, a critical code injection vulnerability in one of npm's most depended-upon packages. protobuf.js is the JavaScript runtime for Protocol Buffers — Google's language-neutral serialization format — used by ~52 million npm installations per week.
The vulnerability was assigned a CVSS 3.1 score of 9.8
(CRITICAL) by NVD, with the vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H — network-based, low complexity,
no privileges required, no user interaction, full compromise of confidentiality, integrity,
and availability. GitHub Security Advisories scored it 8.7 (HIGH) under
CVSS 4.0, citing LOW privilege requirements.
Discovered by security researchers cristianstaicu, alexander-fenster, and sofisl, the vulnerability was classified as CWE-94 (Improper Control of Generation of Code — 'Code Injection'). It was tracked via GHSA-xq3m-2v4x-88gg.
Why it matters: protobuf.js is a foundational piece of the npm ecosystem. It's a transitive dependency of Google Cloud client libraries, the Firebase SDK, gRPC-web, and thousands of other packages. Any application that consumes .proto files or JSON descriptors from untrusted sources is at direct risk of server compromise.
protobuf.js compiles Protocol Buffer definitions (.proto files or JSON descriptors) into JavaScript code at runtime. When you define a message type, protobuf.js generates encode, decode, and toObject functions by embedding type names directly into generated JavaScript strings.
The vulnerability is remarkably simple in retrospect: type names were interpolated into generated code without sanitization. A type name containing characters like backticks, parentheses, or quotes could break out of the string literal context and inject arbitrary JavaScript into the generated function.
// Simplified: how the exploit works
// protobufjs generates code like this:
function encode(message, writer) {
// Type name is interpolated directly:
var TypeName = "` + ATTACKER_CONTROLLED + `";
// ...
}
// With a malicious type name containing:
// ` + process.mainModule.require('child_process').execSync('id') + `
// The generated code becomes:
var TypeName = "` + process.mainModule.require('child_process').execSync('id') + `";
// Which JS evaluates as string concatenation — executing the command!
The fix (PR #2127) is a single line added to the Type constructor in src/type.js:
// Before (vulnerable):
// Type names were used as-is in generated code
// After (patched in 7.5.5 / 8.0.1):
name = name.replace(/\W/g, "");
This regex filters out all non-word characters (anything that is not alphanumeric or underscore) from type names. The commit message explains: "There is no reason why the type name would contain anything other than alphanumeric characters. Filter the remaining characters with a regex."
A second fix (PR #2126) addressed a related attack vector: prototype pollution via the
Message constructor. When a properties object was passed to the constructor,
__proto__ was copied as a regular property, allowing attackers to pollute
Object.prototype:
// Prototype pollution via Message constructor:
const properties = JSON.parse('{"__proto__": {"polluted": "yes"}}');
const message = new protobuf.Message(properties);
// message.__proto__.polluted === "yes"
// Object.prototype is now polluted — affects all objects!
// The fix filters out __proto__ when iterating properties:
// if (key === "__proto__") continue;
The full exploit chain for CVE-2026-41242 follows this path:
Key insight: The vulnerability is in the code generation phase, not in input parsing. Simply loading a malicious .proto file is enough to trigger the injection — you don't need to encode or decode any actual messages. The injection happens at the moment protobuf.js compiles the definition into JavaScript.
| Branch | Affected | Patched | Date |
|---|---|---|---|
| 7.x | <=7.5.4 |
7.5.5 |
Apr 17, 2026 |
| 8.x | ==8.0.0 |
8.0.1 |
Mar 11, 2026 |
The initial fix in 7.5.5 and 8.0.1 was incomplete. Over the following two months, the maintainers disclosed 5 additional CVEs — including code injection bypasses, prototype pollution chains, and CLI-specific vulnerabilities:
| CVE ID | Type | CVSS | Package | Description |
|---|---|---|---|---|
| CVE-2026-41242 | RCE | 9.8 | protobufjs | Code injection through malicious type names in protobuf definitions |
| CVE-2026-44293 | RCE | 7.7 | protobufjs | Code injection through bytes field defaults in generated toObject code |
| CVE-2026-44291 | RCE | 8.1 | protobufjs | Code generation gadget after prototype pollution — attacker-controlled type lookup |
| CVE-2026-44295 | RCE | 8.7 | protobufjs-cli | Code injection in pbjs static output from crafted schema names |
| CVE-2026-54271 | RCE | 8.2 | protobufjs-cli | Bypass of CVE-2026-44295 — JSON descriptor input still produced unsafe references |
| CVE-2026-54269 | DoS | 5.3 | protobufjs | Schema names like `valueOf`, `rpcImpl` collide with runtime helpers |
protobuf.js is one of the most widely used packages on npm with approximately 52 million weekly downloads. It is a transitive dependency of:
The critical risk profile applies to applications that load protobuf definitions from untrusted sources — for example, a service that accepts user-uploaded .proto files, or an API gateway that processes external JSON descriptors. Even if your application only uses hardcoded .proto files, a supply-chain attack that modifies those files would achieve server compromise.
Upgrade to the latest secure versions:
# Check your current version
npm ls protobufjs
# Update to the latest secure version
npm install protobufjs@latest
# Or update specific versions:
# For 7.x users (recommended: jump to latest)
npm install [email protected]
# For 8.x users
npm install [email protected]
# If you use pbjs or pbts in your build pipeline
npm install protobufjs-cli@latest
# Minimum: 1.3.2 (1.x) or 2.5.0 (2.x)
# Latest: 2.5.4
protobuf.js is commonly a transitive dependency. Check if any of your dependencies still pin a vulnerable version:
# Find all protobufjs versions in your dependency tree
npm ls protobufjs
# Check for transitive protobufjs-cli
npm ls protobufjs-cli
# Force resolution if a transitive dep is pinned
npm install [email protected] --save-dev
# Or use overrides in package.json:
// "overrides": {
// "protobufjs": "7.6.4"
// }
# Confirm the version
npm ls protobufjs
# Expected: 7.6.4 or 8.6.3 (or higher)
# For protobufjs-cli
npm ls protobufjs-cli
# Expected: 2.5.4 or higher
If an immediate upgrade is not possible (e.g., due to compatibility constraints):
These mitigations reduce risk but do not eliminate it. The only complete fix is upgrading to a patched protobufjs version. Attackers only need one way in — a lone unpatched service, a forgotten transitive dependency, or a single .proto file from an external source can lead to full server compromise.
| Date | Event |
|---|---|
| Mar 7, 2026 | PR #2126 opened — __proto__ filter in Message constructor |
| Mar 11, 2026 | PR #2127 opened — type name sanitization (/\W/g filter); v8.0.1 released |
| Apr 15, 2026 | Fix cherry-picked to 7.x branch (commit ff7b2af) |
| Apr 17, 2026 | v7.5.5 released — patches CVE-2026-41242 on 7.x |
| Apr 27–28, 2026 | v7.5.6 and v8.0.2 released — follow-up security fixes (CVE-2026-44291, CVE-2026-44293) |
| May 12, 2026 | 5 advisories published: CVE-2026-44291/293/295 + CLI advisories |
| Jun 9–10, 2026 | v7.6.3 / v8.6.2 / v8.6.3 released — CVE-2026-54269 fix and bug fixes |
| Jun 13, 2026 | Latest releases: v7.6.4, v8.6.3 |
The protobuf.js vulnerability chain offers several important takeaways:
CVE-2026-41242 is one of the most significant npm supply-chain security incidents of 2026. A CVSS 9.8 code injection vulnerability in protobuf.js — a package with 52 million weekly downloads — demonstrates how a single unsanitized string interpolation can compromise thousands of applications.
The vulnerability was exacerbated by the chain of 5 follow-up CVEs that bypassed the initial fix, highlighting the importance of comprehensive security reviews over minimal reproducer patches. The protobuf.js maintainers have now fully addressed all known vectors, and the latest versions (7.6.4 and 8.6.3) are secure.
For developers, the key takeaway is clear: protobuf definitions loaded from external
sources are a critical attack surface. Even if you only use hardcoded .proto files,
your transitive dependency graph may be vulnerable. Run npm audit, check
your dependency tree, and update to the latest protobufjs versions today.
I build production applications with modern tools — React, Next.js, Node.js, and TypeScript — with security as a core concern. Let's discuss your project.