/

CVE-2026-54271

Severity:

HIGH RISK

(8.2)

Code Injection (CWE-94) in protobufjs-cli static output

CVE-2026-54271

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution via Generated Artifacts

Severity:

HIGH RISK

(8.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

protobufjs-cli versions prior to 1.3.2 and 2.5.0 can generate JavaScript files that embed attacker-controlled code when given crafted JSON descriptor input, due to incomplete sanitization of unsafe names in static and static-module code generation.

If an attacker can supply or influence the JSON descriptors used by pbjs, the resulting generated code may execute malicious payloads when the output file is later imported or run and the affected APIs are invoked.

Affected context

This vulnerability occurs in development or build environments that:

  • Use protobufjs-cli to generate static or static-module JavaScript code
  • Accept or process pre-parsed JSON descriptors (instead of parsing .proto files directly)
  • Treat generated JavaScript as trusted application code and execute or import it without additional review

The risk materializes when the JSON descriptor content can be influenced by untrusted sources or mixed-trust pipelines, and the generated files are later executed in Node.js, browsers, or bundlers as part of an application.

Exploit preconditions

  • Attack surface: Code-generation pipeline using protobufjs-cli static / static-module targets.
  • Required access: Ability to provide, modify, or influence the JSON descriptor input consumed by pbjs during generation.
  • Trigger point: Running pbjs static or static-module code generation on the crafted JSON descriptor, followed by executing or importing the generated JavaScript and invoking affected APIs.
  • Why exploitation is possible: The name-handling and escaping logic for identifiers and references in the code generator was incomplete, allowing attacker-controlled values from the JSON descriptor to be emitted as raw JavaScript references or code fragments, which are then treated as executable code when the generated file runs.

Why this happens

The underlying issue is an incomplete defense against code injection in code generators, mapped to CWE-94: Improper Control of Generation of Code ('Code Injection').

The protobufjs-cli static code generator takes schema information from JSON descriptors and interpolates it into JavaScript templates.

Because some identifier or reference fields derived from the descriptor were not fully validated, normalized, or safely escaped, crafted values could break out of the intended syntactic context and inject arbitrary expressions into the output.

This pattern reflects a broader bug class where template-based generators treat partially untrusted metadata as inert text, but use it in contexts (identifiers, property paths, or expression positions) that the JavaScript engine interprets as executable program code.

Potential impact

  • Generated JavaScript may execute attacker-controlled code when imported or run.
  • Compromise of build or deployment environments that automatically run or bundle generated code.
  • Execution of arbitrary commands or actions in Node.js environments using the generated code.
  • Data exfiltration, privilege escalation, or lateral movement via malicious logic hidden in generated APIs.
  • Supply-chain style attacks where compromised descriptors poison downstream consumers of the generated artifacts.

General mitigation guidance

Mitigation centers on treating code generation input as potentially hostile and hardening generator templates:

  • Normalize and strictly validate schema-derived names and references before injecting them into code templates, enforcing conservative character sets and structural constraints.
  • Use context-aware escaping routines for all variable substitutions that influence identifiers, property paths, or expressions in generated JavaScript.
  • Separate trusted and untrusted stages of schema processing; only allow code generation from descriptors that have passed validation and originate from trusted sources.
  • Reduce implicit trust in generated artifacts by incorporating review or signing steps, especially when descriptors come from third parties or automated pipelines.
  • Apply least-privilege and sandboxing where generated code is executed (e.g., constrained runtimes, limited I/O) to minimize blast radius if a similar issue reappears.

How teams detect issues like this

Effective detection approaches can combine static analysis, build-time checks, and review practices:

  • Use static analysis or grep-based rules to scan protobufjs-cli templates or output for unsafe interpolation patterns, such as direct insertion of descriptor-derived values into executable contexts without sanitization.
  • Add CI jobs that inspect generated JavaScript for unexpected constructs (e.g., eval, Function, process or fs access) in code that should only consist of serialization logic.
  • During security code review, flag any code-generation step that accepts JSON descriptors from mixed-trust sources and verify that identifiers and references are strictly validated.
  • Employ automated SAST tools that recognize JavaScript code injection patterns and can inspect both generator source code and committed generated artifacts.
  • Establish policy controls that prevent unchecked third-party or user-controlled schema descriptors from feeding into production code-generation pipelines.

Sources

SourceLink
github.comgithub.com/protobufjs/protobuf.js/security/advisories/GHSA-pr59-h9ph-3fr8

Frequently asked

questions

Indirectly. The vulnerable component is typically used in build or development pipelines, not as an exposed network service. However, an attacker who can supply or influence JSON descriptors consumed by pbjs—for example via a compromised repository, artifact, or CI integration—can cause malicious code to be generated and later executed downstream.

The attacker must be able to provide or modify the pre-parsed JSON descriptor input that protobufjs-cli uses during static code generation. This could occur through commit access to a schema repository, control over a dependency providing descriptors, or any other pathway by which descriptors enter the build process.

Ensure that the code generator strictly validates and safely escapes all descriptor-derived names and references before embedding them into JavaScript, and avoid treating any schema metadata as inherently safe.

Additionally, restrict code generation to descriptors from trusted sources and consider re-generating code with a hardened generator when fixes are applied.

Adopt a security mindset for build and code-generation tooling: treat all generator inputs as untrusted, implement input validation plus context-aware escaping, and add automated checks that examine generated artifacts for suspicious patterns.

Layer this with supply-chain security practices such as signed artifacts, protected schema repositories, and CI policies that limit the introduction of unreviewed schemas into production builds.

Find out what's already
exploitable in your codebase.