Summary
protobufjs used plain JavaScript objects with inherited prototypes for internal type lookup tables when compiling protobuf definitions into encode/decode functions.
In environments where Object.prototype is already polluted, attacker-controlled inherited properties can be treated as valid protobuf type metadata, causing untrusted strings to be emitted into generated JavaScript code and enabling potential code injection.
Affected context
This vulnerability affects applications that use protobufjs code generation (static or runtime) in JavaScript/TypeScript environments where Object.prototype may be modified by other code or dependencies.
It is most relevant when:
- protobufjs compiles .proto definitions into JavaScript encode/decode functions
- The runtime environment allows or has already experienced prototype pollution
- Generated code or code snippets are treated as executable JavaScript, either directly or via dynamic evaluation patterns
Exploit preconditions
- Attack surface: Applications using protobufjs to generate or compile protobuf encode/decode functions.
- Required access: Ability to influence Object.prototype or otherwise introduce polluted inherited properties into the process (e.g., via another vulnerability, malicious dependency, or untrusted plugin/module).
- Trigger point: Execution of protobufjs compilation or generation routines that read from internal type lookup tables backed by plain objects.
- Why exploitation is possible: The internal lookup tables rely on plain objects that inherit from Object.prototype. If the global prototype is polluted with attacker-controlled properties, those inherited keys can be resolved as legitimate type information, and their values can be emitted as part of generated JavaScript code, enabling injection of untrusted strings into executable contexts.
Why this happens
The core issue stems from using plain JavaScript objects (with default prototypes) as lookup tables for protobuf type metadata, instead of using structures that do not inherit from Object.prototype.
Because these tables inherit from the global object prototype chain, any pre-existing prototype pollution can introduce attacker-controlled properties that appear as valid lookup results.
When protobufjs translates these lookups into generated encode/decode functions, it effectively embeds unvalidated, inherited values into JavaScript code, aligning with CWE-94: Improper Control of Generation of Code ('Code Injection'), where untrusted input influences the construction of executable code.
Potential impact
- Injection of attacker-controlled strings into generated JavaScript encode/decode functions
- Execution of arbitrary code if the generated output is evaluated or executed in a trusted context
- Tampering with serialization/deserialization logic, potentially leading to data corruption or logic manipulation
- Escalation of impact when combined with other vulnerabilities that allow prototype pollution or dynamic code evaluation
General mitigation guidance
Mitigations generally focus on decoupling internal data structures from the global prototype chain and reducing trust in dynamically generated code:
- Use prototype-free data structures (e.g., objects created with null prototypes or Map-like structures) for lookup tables that may be influenced by external input.
- Avoid designing systems where generated JavaScript code is treated as executable content without strict validation and sanitization.
- Reduce or eliminate dynamic evaluation patterns (such as eval-like constructs) when working with generated code artifacts.
- Apply defense-in-depth by hardening the environment against prototype pollution and ensuring shared prototypes are not used as a communication channel for untrusted data.
How teams detect issues like this
Detection typically involves both code-level and environment-level analysis:
- Static analysis rules that flag use of plain objects as lookup tables in security-sensitive code generation paths, especially where Object.prototype inheritance is intact.
- Code review practices that look for patterns where untrusted values influence generated code templates, function bodies, or dynamic function constructors.
- Security testing for prototype pollution vectors, including automated tests that inject unexpected properties into Object.prototype and observe resulting behavior in protobufjs-based components.
- Use of automated security review tools or linters configured to detect dangerous combinations of prototype inheritance and code generation.

