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
summaryfield 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.

