Summary
Orval, a tool that generates type-safe JavaScript/TypeScript clients from OpenAPI or Swagger specs, contains a code injection flaw in its jsStringEscape routine in versions 7.19.0 through 7.20.x and 8.0.x–8.1.x.
Because certain non-alphanumeric characters like []()!+ are not escaped, an attacker who controls OpenAPI description content can craft JSFuck-style payloads that result in arbitrary JavaScript execution in the generated client code.
Affected context
This vulnerability appears in projects that:
- Use Orval to generate JavaScript/TypeScript clients from OpenAPI v3 or Swagger v2 specifications, and
- Incorporate generated clients directly into web applications, Node services, or shared SDKs, and
- Allow all or part of the OpenAPI description (e.g., operation names, descriptions, error messages, or other text fields embedded into code) to be influenced by untrusted or semi-trusted actors, such as upstream services, external API providers, or user-driven content.
The issue manifests at code generation time, where OpenAPI-provided strings are embedded into JavaScript source files using jsStringEscape, which does not fully neutralize all characters that can construct executable JavaScript.
Exploit preconditions
- Attack surface: The OpenAPI/Swagger specification content that Orval consumes, including any fields that Orval places into generated JS/TS source as string literals or inline code fragments.
- Required access: Ability to modify or influence parts of the OpenAPI spec used by a target project. This may be via:
- Direct control of the spec file in a multi-tenant or plugin-based system
- Control over an upstream service that auto-generates the spec
- CI/CD pipelines that fetch the spec from remote or user-supplied sources
- Trigger point: Running Orval to generate client code with a tainted specification, then building and running the resulting application that imports the generated client modules.
- Why exploitation is possible: jsStringEscape focuses on escaping quotes and certain obvious metacharacters but leaves characters such as
[]()!+untreated. JavaScript's flexible syntax allows the JSFuck technique to construct arbitrary code using only these characters; when such crafted payloads are embedded into generated source without full neutralization, the JavaScript engine interprets them as executable code.
Why this happens
The underlying issue is an incomplete neutralization of user-controlled input before embedding it into executable JavaScript, aligning with CWE-94: Improper Control of Generation of Code ('Code Injection').
Orval's jsStringEscape routine attempts to sanitize values by escaping quotes and some control characters so they can safely appear inside string literals. However, it assumes that neutralizing quotes is sufficient to prevent code execution. In JavaScript, the JSFuck technique demonstrates that arbitrary expressions can be composed only from a small set of punctuation characters ([]()!+ and similar), which remain unescaped.
As a result, attacker-controlled specification fields are treated as inert data but are inserted into code in a way that the JavaScript parser interprets as executable syntax, creating an injection channel during generation rather than at runtime.
Potential impact
- Execution of arbitrary JavaScript in applications that import the generated Orval client.
- Execution of attacker-controlled code in Node.js services using the generated clients, potentially leading to server compromise.
- Supply-chain style attacks where a poisoned OpenAPI spec leads to backdoored SDKs distributed to downstream consumers.
- Exfiltration or manipulation of sensitive data accessed via the generated client, including tokens, API keys, or user information.
- Lateral movement within build or runtime environments if generated code runs with elevated privileges or broad network access.
General mitigation guidance
Effective mitigation focuses on treating all specification-derived content as untrusted and hardening code-generation boundaries:
- Prefer escaping strategies that are context-aware, ensuring that any value inserted into JavaScript/TypeScript is encoded for its exact syntactic position (e.g., strict string-literal encoding that does not allow raw punctuation to be interpreted as operators).
- Constrain which OpenAPI fields are allowed to flow into generated source; avoid embedding attacker-controllable fields as-is in runtime code paths (for example, limit to strictly validated identifiers and simple messages).
- Apply strict validation and normalization to any externally sourced OpenAPI spec before feeding it to Orval, rejecting or stripping unexpected characters in fields destined for code.
- Design generation templates so that specification content is never concatenated into executable expressions; ensure it is always treated as plain data (e.g., configuration objects, mapping tables) rather than inline logic.
- Isolate the generated client's privileges: run it with least privilege, avoid giving it direct access to high-value secrets, and separate its responsibilities so that compromise has limited blast radius.
How teams detect issues like this
Detection generally combines static analysis of generated code with scrutiny of the code-generation templates and input specification:
- Use static analysis or linters to search generated JS/TS for suspicious patterns derived from specification fields, such as unusual punctuation-only expressions or JSFuck-like constructs.
- Review Orval template usage to identify locations where spec fields are interpolated into code, looking for raw insertions into string literals, function bodies, or template strings.
- Implement CI checks that flag non-alphanumeric or unexpected characters in OpenAPI fields that are known to influence generated code structure (e.g., operationId, summary, description, error messages).
- Employ security-focused code review of both the generator configuration and any custom templates or hooks that might pass data directly into JavaScript without proper encoding.
- Integrate SAST or supply-chain scanning tools that can inspect generated artifacts for known code injection signatures or patterns associated with JSFuck payloads.

