protobufjs-cli: Code injection in pbjs static output from crafted JSON descriptor names
Description
Summary
A previous fix for unsafe name handling in pbjs static / static-module code generation was incomplete. Affected versions of protobufjs-cli could still emit unsafe JavaScript references when generating static output from crafted JSON descriptor input. The common case of parsing schemas from .proto files is not affected.
This is a bypass of GHSA-6r35-46g8-jcw9 / CVE-2026-44295.
Impact
An attacker who can provide or influence pre-parsed JSON descriptors passed to pbjs static code generation may be able to cause generated JavaScript output to contain attacker-controlled code.
The injected code may execute if the generated file is later executed or imported and an affected generated API path is invoked.
Preconditions
- The application or build process must run
pbjsstatic code generation on a pre-parsed JSON descriptor influenced by an attacker. - The generated JavaScript file must subsequently be executed or imported.
- An affected generated API path must be invoked.
Workarounds
Do not run affected versions of pbjs static or static-module generation on untrusted JSON descriptors. If untrusted JSON descriptors must be accepted, validate descriptor-derived names before code generation and reject names that could not have been produced by parsing a valid .proto file. Running code generation in an isolated environment can reduce impact.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Affected products
2- Range: >= 2.0.0, <= 2.4.2
Patches
Vulnerability mechanics
Root cause
"Incomplete sanitization of user-controlled names in `pbjs` static code generation allows injection of arbitrary JavaScript into generated output."
Attack vector
An attacker who can supply a crafted JSON descriptor to `pbjs` static code generation can inject arbitrary JavaScript into the generated output. The root name (via the `--root` option) or type names containing dots, special characters, or JavaScript prototype property names like `__proto__` or `constructor` could be used to inject code. The injected code executes when the generated file is imported or executed and an affected API path is invoked. This bypasses the previous fix (GHSA-6r35-46g8-jcw9 / CVE-2026-44295) because the earlier fix did not address all code paths where unsafe names were concatenated into generated JavaScript.
Affected code
The vulnerability resides in `cli/targets/static.js` and `cli/targets/json-module.js` where the `rootProp` variable was constructed using `util.safeProp()` (which could produce unsafe dot-notation references) instead of bracket notation with `JSON.stringify()`. Additionally, `buildFunction()` in `cli/targets/static.js` concatenated `type.fullName` directly into generated code without escaping, and `cli/util.js` did not sanitize the `lint` option for comment terminators. The patch also adds duplicate-name detection in `buildNamespace()` and changes `src/roots.js` to use `Object.create(null)` to avoid prototype pollution.
What the fix does
The patches replace `util.safeProp()` with bracket notation using `JSON.stringify()` for root property access, preventing unsafe dot-notation references. A new `objectPath()` helper and `rootMemberRef()` function are introduced to build AST member expressions from escaped path segments rather than concatenating `type.fullName` directly. The `lint` option in `cli/util.js` is now sanitized by escaping `*/` sequences to prevent comment injection. Duplicate generated name detection is added in `buildNamespace()` to reject ambiguous names. `src/roots.js` is changed to `Object.create(null)` to avoid prototype pollution from dictionary root names.
Preconditions
- configThe application or build process must run `pbjs` static code generation on a pre-parsed JSON descriptor influenced by an attacker.
- authThe generated JavaScript file must subsequently be executed or imported.
- inputAn affected generated API path must be invoked.
Generated on Jun 15, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
2News mentions
0No linked articles in our index yet.