Summary
Orval, a tool that generates type-safe JavaScript/TypeScript clients from OpenAPI and Swagger specs, contains a code injection flaw in the enum generation path for versions prior to 7.19.0 up to 8.0.2.
When untrusted OpenAPI specifications are processed, attacker-controlled data in x-enumDescriptions can be embedded without proper escaping into generated client code, potentially leading to arbitrary code execution wherever those generated clients are built or executed.
Affected context
The vulnerability appears in environments where Orval is used to generate TypeScript/JavaScript clients from OpenAPI v3 or Swagger v2 specifications, and where those specifications are not fully trusted or may be supplied by external parties or automated pipelines.
The issue specifically affects the getEnumImplementation() logic in @orval/core, in the code path that produces const enum implementations for schema enums and embeds x-enumDescriptions directly into the generated code.
Systems that automatically generate, build, and deploy clients from incoming or shared API specifications—particularly in CI/CD or shared API design platforms—are the most exposed.
Exploit preconditions
- Attack surface: Orval's OpenAPI/Swagger specification input, especially fields used to generate enums (
x-enumDescriptions). - Required access: Ability to supply or modify the OpenAPI/Swagger specification that Orval consumes (e.g., via a shared API design repo, spec upload service, or compromised upstream spec).
- Trigger point: Running Orval to generate clients from the malicious specification and then building or executing the generated TypeScript/JavaScript code.
- Why exploitation is possible: The
x-enumDescriptionsfield is interpolated into TypeScript enum implementation code without proper escaping or sanitization, allowing attacker-controlled text to break out of string or comment contexts and introduce arbitrary executable code.
Why this happens
This vulnerability stems from improper neutralization of special elements used in code generation, mapping to CWE-94: Improper Control of Generation of Code and CWE-77: Improper Neutralization of Special Elements used in a Command.
The getEnumImplementation() function in @orval/core treats x-enumDescriptions as harmless descriptive metadata, but it embeds this data directly into generated TypeScript/JavaScript source for const enum declarations without encoding or validation.
Because the generator emits raw code rather than strictly formatted string literals or comments with robust escaping, crafted descriptions can terminate existing constructs and inject new statements or expressions.
This pattern is typical of template-based code generators that concatenate untrusted input into language syntax without escaping, effectively turning data from the specification into executable logic in the generated clients.
Potential impact
- Execution of arbitrary JavaScript/TypeScript code during build steps (e.g., when compiling generated clients).
- Execution of attacker-supplied code at runtime wherever the generated client library is loaded or run.
- Compromise of CI/CD agents or developer workstations that process malicious specifications.
- Data exfiltration or manipulation from applications using the generated clients.
- Lateral movement within development or deployment environments via compromised build artifacts.
General mitigation guidance
Effective mitigation centers on treating specification content as untrusted input and ensuring it cannot become executable code without strict controls:
- Apply robust escaping when embedding specification fields into generated code, especially for comments, string literals, and identifiers.
- Constrain which specification extensions and fields are allowed to influence code structure; treat descriptive metadata (like
x-enumDescriptions) as data-only, not as code. - Prefer templating approaches that separate code structure from data (e.g., using safe template engines or AST-based generation) instead of raw string concatenation.
- Introduce validation layers for incoming OpenAPI/Swagger specs, rejecting or normalizing unexpected or malformed extension fields.
- Run code generation and subsequent builds under least-privilege accounts and isolated environments to limit blast radius if a spec is malicious.
How teams detect issues like this
Detection generally focuses on both source-level patterns and build-time behaviors:
- Use static analysis or linters on the Orval codebase and templates to flag direct concatenation of untrusted specification fields into output code without escaping.
- Add safeguards in code review checklists for generators: any place where spec content is injected into output code should be examined for proper sanitization and context-aware encoding.
- Implement automated checks in CI pipelines to scan generated client code for suspicious constructs originating from metadata fields (e.g., unexpected statements in enum descriptions).
- Monitor build logs and diffs of generated artifacts for anomalous changes when specs are updated, especially around enums and documentation blocks.
- Employ repository or pipeline policies that restrict who can modify API specifications that feed code generation.

