/

CVE-2026-24132

Severity:

CRITICAL RISK

(9.8)

Code Injection in Orval Mock Generator

CVE-2026-24132

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-77, CWE-94

Impact:

Arbitrary Code Injection into Generated TypeScript/JavaScript Artifacts

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 versions 7.19.0 and below, and 8.0.0-rc.0 through 8.0.2, allow untrusted OpenAPI specifications to inject arbitrary TypeScript/JavaScript into generated mock files by abusing const values on schema properties.

Because these const values are interpolated into the mock scalar generator without proper escaping or type-safe serialization, attacker-controlled code can end up in interface definitions and faker/MSW handlers, turning downstream use of the generated code into a code execution risk.

Affected context

This vulnerability affects workflows where Orval is used to generate TypeScript/JavaScript clients and mocks from OpenAPI v3 or Swagger v2 specifications, especially in CI/CD pipelines, monorepos, or codegen-based development setups.

The risk materializes when OpenAPI specifications are sourced from, or can be modified by, untrusted or semi-trusted parties—such as external API providers, shared specs in multi-tenant environments, or specs pulled automatically from remote endpoints.

In those scenarios, const keywords on schema properties can carry malicious payloads that are inserted into the mock generation path without safe encoding, contaminating generated code consumed by developers, test harnesses, or build systems.

Exploit preconditions

  • Attack surface: The OpenAPI/Swagger specification input to Orval, particularly schema properties using the const keyword.
  • Required access: Ability to provide or modify an OpenAPI specification that Orval will consume—this may be via source control, API design tools, remote spec URLs, or integration points that auto-sync specs.
  • Trigger point: Running Orval's code generation with mock generation enabled, which invokes getMockScalar in packages/mock/src/faker/getters/scalar.ts and emits mock interfaces and faker/MSW handlers.
  • Why exploitation is possible: Const values from the spec are interpolated directly into TypeScript/JavaScript output without escaping or type-safe serialization, so attacker-controlled text can break out of expected literals and become executable code in the generated artifacts.

Why this happens

The underlying bug is a classic code injection issue where untrusted data is embedded into generated source code without correct sanitization or encoding.

In this case, Orval's faker-based mock generator takes const values from schema properties and passes them into getMockScalar, which then interpolates them into TypeScript/JavaScript files as if they were safe scalar values.

Because these values are not treated as pure data—no enforced quoting, escaping, or serialization—they can contain syntactically valid code that changes the structure of the emitted program. This maps to:

  • CWE-94: Improper Control of Generation of Code, since user inputs directly influence generated code content and structure.
  • CWE-77: Improper Neutralization of Special Elements, in the sense that language metacharacters are not neutralized before inclusion in code, allowing injection of arbitrary constructs.

Potential impact

  • Injection of arbitrary TypeScript/JavaScript into generated mock files.
  • Execution of attacker-controlled code during test runs, local development, or build steps that compile or execute the generated code.
  • Compromise of developer workstations or CI/CD runners that build or run the generated mocks.
  • Contamination of frontend or backend test environments via malicious MSW/faker handlers.
  • Potential lateral movement inside development networks if builds or tests have access to sensitive internal services.

General mitigation guidance

Mitigation focuses on treating OpenAPI specifications as untrusted input and hardening the code generation pipeline:

  • Enforce strict data/metadata separation when emitting code: always serialize untrusted values using safe, language-specific encoding (e.g., JSON/string serialization) before inserting them into source files.
  • Apply robust escaping for all dynamic substitutions in templates, ensuring special characters and control sequences cannot break out of string or literal contexts.
  • Reduce trust in external or remote API specifications by vetting or mirroring them, rather than consuming them directly in production codegen pipelines.
  • Restrict or avoid using expressive fields (such as const, enum, or description-like extensions) from untrusted specs in code generation paths that produce executable constructs.
  • Run code generation in constrained environments with least privilege and limited access to secrets or critical infrastructure, so that even if code injection occurs, blast radius is minimized.

How teams detect issues like this

Effective detection combines code review, automated scanning, and policy controls:

  • Static analysis of templates and codegen paths: Look for string interpolation or template usage that incorporates spec fields (e.g., const, enum, descriptions) into generated code without explicit escaping or serialization.
  • Automated scanning of generated artifacts: Use linters, AST-based analyzers, or SAST tools on the generated TypeScript/JavaScript to flag suspicious constructs originating from spec-controlled fields.
  • Repository and pipeline policies: Enforce rules that prevent direct consumption of unvetted OpenAPI specs from external sources in CI; require reviews or signing/attestation of specifications before they feed codegen.
  • Differential review of generated diffs: In code review, pay attention to unexpected structural changes in generated mocks—new function bodies, imports, or global statements that trace back to spec modifications.

Sources

SourceLink
github.comgithub.com/orval-labs/orval/commit/44ca8c1f5f930a3e4cefb6b79b38bcde7f8532a5
github.comgithub.com/orval-labs/orval/commit/6d8ece07ccb80693ad43edabccb3957aceadcd06
github.comgithub.com/orval-labs/orval/commit/9b211cddc9f009f8a671e4ac5c6cb72cd8646b62
github.comgithub.com/orval-labs/orval/pull/2828
github.comgithub.com/orval-labs/orval/pull/2829
github.comgithub.com/orval-labs/orval/pull/2830
github.comgithub.com/orval-labs/orval/releases/tag/v7.20.0
github.comgithub.com/orval-labs/orval/releases/tag/v8.0.3
github.comgithub.com/orval-labs/orval/security/advisories/GHSA-f456-rf33-4626

Frequently asked

questions

It can be, if an attacker can influence the OpenAPI specification that Orval consumes—for example, by controlling a remote spec URL, compromising an API design tool, or contributing specs in a shared repository that are later used in automated code generation.

Not necessarily. The key requirement is the ability to modify or supply the spec. In some environments that may require authenticated access (e.g., committing to a repo), but in others the spec might be fetched from an unauthenticated external endpoint, making it easier for an attacker to tamper with.

The safest approach is to treat all spec-driven values as data and never as raw code—always serialize/escape them before inserting into generated artifacts, and avoid generating executable constructs directly from free-form or highly expressive fields like const without strict validation.

Adopt a secure code generation design: clearly separate template logic from untrusted inputs, implement centralized escaping/serialization utilities, mandate security review for all codegen paths that embed user-controlled values, and restrict direct consumption of external specs by enforcing review, signing, or controlled mirroring.

Find out what's already
exploitable in your codebase.