Summary
protobufjs versions prior to 8.0.1 and 7.5.5 contain a code injection flaw where attacker-controlled values in protobuf type definitions can be compiled into executable JavaScript.
When affected definitions are used for decoding, this injected code may execute within the application's runtime, enabling full remote code execution in environments that consume untrusted or indirectly influenced protobuf schemas.
Affected context
This vulnerability arises in applications that use protobufjs to compile and decode protobuf schemas which are, in whole or in part, influenced by untrusted or semi-trusted sources.
It is most relevant where:
- Protobuf definitions are loaded at runtime (e.g., from configuration files, databases, network sources, or plugins), and
- The
typefields within message definitions can be modified or supplied by an attacker or a compromised upstream system.
In such contexts, the library's compilation and decoding mechanisms may treat these definitions as code templates, turning crafted schema data into executable JavaScript.
Exploit preconditions
- Attack surface: The schema-loading or definition-compilation path in applications that use protobufjs to compile protobuf definitions into JavaScript.
- Required access: Ability to inject, modify, or control protobuf definitions or their
typefields before compilation/decoding (e.g., editing schema files, influencing remote schema registries, or man-in-the-middle of schema distribution). - Trigger point: Decoding operations that rely on the compiled protobuf definitions using protobufjs, which automatically execute the generated JavaScript code.
- Why exploitation is possible: Earlier protobufjs versions treat
typefields in definitions as inputs to code generation logic without sufficient sanitization or constraints, effectively allowing attacker-supplied text to be embedded into executable JavaScript functions.
Why this happens
The root cause is an unsafe code generation pattern where user-influenced protobuf type fields are incorporated into dynamically constructed JavaScript without robust validation or sanitization.
This maps directly to CWE-94: Improper Control of Generation of Code, where an application generates code based on external input and then executes it in the same trust context.
Instead of treating schema data as passive configuration, the library's compilation step effectively treats parts of the schema as code fragments, enabling arbitrary code injection when those compiled definitions are used during object decoding.
Potential impact
- Remote code execution in the context of the process using protobufjs.
- Full compromise of the affected service, including data exfiltration, modification, or destruction.
- Use of the compromised service as a pivot point for lateral movement within the hosting environment or network.
- Deployment of additional malware or backdoors within the application's infrastructure.
- Integrity compromise of data processed through affected protobuf schemas.
General mitigation guidance
Effective mitigation focuses on reducing trust in schema inputs and removing opportunities for user-controllable data to influence code generation:
- Prefer schema loading patterns where protobuf definitions are static, version-controlled assets, not dynamically retrieved from untrusted sources.
- Constrain who and what can modify protobuf definitions by enforcing strict change-control and code review on schema files.
- Avoid dynamic code generation based on raw schema fields; rely on APIs and code paths that treat schema definitions as data rather than templates for executable code.
- Introduce validation layers that inspect protobuf definitions before compilation, rejecting or stripping suspicious
typevalues or patterns. - Run services that process potentially untrusted schemas with least privilege, strong sandboxing, and process isolation, so that even if a similar issue arises, the blast radius is reduced.
How teams detect issues like this
Organizations can look for this class of issue using a mix of static and process-level checks:
- Static analysis and code review:
- Flag uses of dynamic code generation mechanisms in protobufjs integration code (e.g., constructing functions or using code templates from schema fields).
- Review schema handling paths to ensure that
typefields and related metadata are not sourced from untrusted locations without validation. - Policy and configuration checks:
- Enforce policies that prohibit runtime downloading or accepting of arbitrary protobuf schema definitions in production systems.
- Use build-time checks to ensure that only vetted, local schema files are compiled and packaged with the application.
- Runtime monitoring:
- Monitor for anomalous behavior in services using protobufjs, such as unexpected outbound network connections, unusual file system access, or invocation of system utilities during decoding operations.
- Apply application-level logging around schema loading and compilation events to help identify when unapproved definitions are being processed.
Automated security testing tools, including SAST and configuration scanners, can help flag risky dynamic-code-generation patterns in the surrounding application code, even when they originate from third-party libraries.

