/

CVE-2026-22785

Severity:

CRITICAL RISK

(9.8)

Command Injection / Code Generation Injection

CVE-2026-22785

Analyzed

Vulnerability type

Category:

Command Injection / Code Generation Injection

CWE:

CWE-77

Impact:

Arbitrary Code Execution in Generated Client Context

Severity:

CRITICAL RISK

(9.8)

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

Orval's MCP server generator previously inserted the OpenAPI summary field directly into generated TypeScript/JavaScript without proper escaping.

A malicious API specification could break out of the intended string literal and inject arbitrary code into the generated client, which may execute when the generated code is built or run.

Affected context

This vulnerability affects environments where:

  • Orval is used to generate MCP server code from OpenAPI v3 or Swagger v2 specifications.
  • The OpenAPI specifications can be influenced, supplied, or modified by untrusted or semi-trusted parties (e.g., imported specs, third‑party APIs, or CI pipelines consuming remote specs).
  • The generated TypeScript/JavaScript code is built, published, or executed without a manual security review.

The risk is especially relevant in automated code generation workflows and supply-chain scenarios where specifications are treated as data, but end up driving code that will execute.

Exploit preconditions

  • Attack surface: The Orval MCP server code generator, when processing OpenAPI/Swagger documents.
  • Required access: Ability to provide or modify an OpenAPI specification consumed by Orval (e.g., via repository contribution, CI configuration, remote spec URL, or compromised upstream spec).
  • Trigger point: Running Orval to generate MCP server code and then building or executing the generated TypeScript/JavaScript.
  • Why exploitation is possible: The summary field from the specification is interpolated into generated source via naive string concatenation, without escaping or validation. This permits an attacker‑controlled summary to terminate the intended string literal and inject arbitrary code into the generated file.

Why this happens

The core issue is unsafe handling of untrusted text when generating executable source code.

Orval's MCP server generator treats the OpenAPI summary metadata as benign documentation but in practice embeds it directly into TypeScript/JavaScript code without sanitization or context-aware escaping.

This design flaw maps to CWE-77: Command Injection, and more broadly to code generation injection, where attacker-controlled strings are concatenated into executable code templates, allowing them to alter the structure of the resulting program rather than remaining data within it.

Potential impact

  • Execution of arbitrary code during build or runtime of the generated MCP server.
  • Compromise of development machines or CI/CD runners that build or test the generated code.
  • Insertion of backdoors or logic bombs into the generated client or downstream applications.
  • Data exfiltration, tampering, or impersonation conducted through the compromised generated server.
  • Supply-chain attacks where malicious behavior is propagated to consumers of generated artifacts.

General mitigation guidance

Effective mitigation centers on treating all specification fields as untrusted input and isolating them from executable contexts:

  • Use strict, context-aware escaping when embedding specification fields into code (e.g., escape characters for string literals, templates, and comments as required by the target language).
  • Prefer structured template rendering rather than ad-hoc string concatenation when generating source code.
  • Separate data and code by keeping user-controlled content in non-executable locations (e.g., external resource files, well-escaped comments).
  • Limit trust in external or third-party OpenAPI specifications; treat them similarly to untrusted user input.
  • Apply least privilege to build and generation environments so that, if code generation is abused, the impact is constrained.

How teams detect issues like this

Detection focuses on both code-level patterns and supply-chain behaviors:

  • Static analysis: Scan code generators for string concatenation patterns that mix untrusted specification fields with executable syntax (e.g., constructing function bodies, command lines, or dynamic imports).
  • Template review: Inspect templates used for MCP server generation to ensure all interpolated fields are escaped according to the target language rules.
  • Policy enforcement: Introduce CI checks that flag code generation steps using remote or unverified OpenAPI specs, requiring review or pinning to vetted sources.
  • Repository monitoring: Review diffs of generated code for unexpected structural changes (e.g., new imports, eval-like constructs, or suspicious function calls that originate from metadata fields).
  • Automated SAST or custom linters can be configured to detect likely injection patterns in both generators and generated artifacts.

Sources

SourceLink
github.comgithub.com/orval-labs/orval/commit/80b5fe73b94f120a3a5561952d6d4b0f8d7e928d
github.comgithub.com/orval-labs/orval/security/advisories/GHSA-mwr6-3gp8-9jmj

Frequently asked

questions

It can be, if an attacker can cause your Orval setup to consume a malicious OpenAPI specification remotely (for example, via a URL, a compromised dependency, or a pull request feeding a spec into your CI). Once the malicious spec is used to generate code and that code is built or run, the injected payload can execute.

The attacker needs the ability to influence or replace the OpenAPI/Swagger specification used by Orval's MCP server generator. This could be through direct repository access, control over a referenced remote spec, or any mechanism that lets them modify the spec before generation.

The safest approach is to ensure that all specification fields, including summary, are treated as untrusted input and are properly escaped or encoded before being inserted into generated code. Code generation should rely on robust templating with context-aware escaping, avoiding raw string concatenation of spec content into executable sections.

Adopt a secure-by-design approach to code generation: never embed untrusted text directly into executable code, enforce strict escaping rules in templates, lock down the provenance of specifications, and add automated checks (linting, SAST, and code review policies) that specifically look for injection-prone patterns in both generators and generated outputs.

Find out what's already
exploitable in your codebase.