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
constkeyword. - 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
getMockScalarinpackages/mock/src/faker/getters/scalar.tsand 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.

