/

CVE-2026-108551

Severity:

CRITICAL RISK

(9.8)

Code Injection (CWE-94) in OpenAPI TypeScript Codegen

CVE-2026-108551

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary JavaScript Execution

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

A critical code injection vulnerability in openapi-typescript-codegen allows attacker-controlled OpenAPI documents to introduce JavaScript into generated client source code. When the generated client is imported or a vulnerable service method is called, the injected code may execute in the consuming environment.

A critical code injection vulnerability in openapi-typescript-codegen allows attacker-controlled OpenAPI documents to introduce JavaScript into generated client source code. When the generated client is imported or a vulnerable service method is called, the injected code may execute in the consuming environment.

Affected context

The vulnerability affects workflows that generate TypeScript clients from OpenAPI documents using openapi-typescript-codegen through version 0.31.0. Risk is present when an OpenAPI document or any of its relevant metadata fields can be supplied or modified by an untrusted party and generated values are inserted into JavaScript string literals without sufficient escaping.

The vulnerability affects workflows that generate TypeScript clients from OpenAPI documents using openapi-typescript-codegen through version 0.31.0. Risk is present when an OpenAPI document or any of its relevant metadata fields can be supplied or modified by an untrusted party and generated values are inserted into JavaScript string literals without sufficient escaping.

Exploit preconditions

  • Attack surface: OpenAPI client generation and subsequent use of the generated JavaScript or TypeScript code
  • Required access: Ability to control or modify an OpenAPI document, including selected path, parameter, server, or metadata values
  • Trigger point: Importing the generated client or invoking affected generated service methods
  • Why exploitation is possible: Unescaped document values are interpolated into single-quoted JavaScript string literals, allowing input to alter generated source structure
  • Attack surface: OpenAPI client generation and subsequent use of the generated JavaScript or TypeScript code
  • Required access: Ability to control or modify an OpenAPI document, including selected path, parameter, server, or metadata values
  • Trigger point: Importing the generated client or invoking affected generated service methods
  • Why exploitation is possible: Unescaped document values are interpolated into single-quoted JavaScript string literals, allowing input to alter generated source structure

Why this happens

The underlying bug is an unsafe code-generation pattern in which values originating from an OpenAPI document are inserted into JavaScript source without context-aware escaping or safe serialization. Values containing JavaScript string delimiters can change the intended literal boundary and introduce executable code. This behavior maps to CWE-94: Improper Control of Generation of Code, because data intended for generated output is allowed to influence executable program structure.

The underlying bug is an unsafe code-generation pattern in which values originating from an OpenAPI document are inserted into JavaScript source without context-aware escaping or safe serialization. Values containing JavaScript string delimiters can change the intended literal boundary and introduce executable code. This behavior maps to CWE-94: Improper Control of Generation of Code, because data intended for generated output is allowed to influence executable program structure.

Potential impact

  • Arbitrary JavaScript may execute in environments that import or invoke the generated client
  • Sensitive credentials, source code, or environment data could be exposed
  • Generated applications or build pipelines could be compromised
  • Downstream users may receive tampered client libraries through a software supply chain
  • Integrity of API integrations and generated artifacts could be affected
  • Arbitrary JavaScript may execute in environments that import or invoke the generated client
  • Sensitive credentials, source code, or environment data could be exposed
  • Generated applications or build pipelines could be compromised
  • Downstream users may receive tampered client libraries through a software supply chain
  • Integrity of API integrations and generated artifacts could be affected

General mitigation guidance

Mitigation generally focuses on treating OpenAPI documents as untrusted data and preventing their contents from becoming executable source structure.

Common defensive patterns include:

  • Serializing generated string values with context-appropriate, standards-compliant escaping
  • Using structured AST or template-generation mechanisms that separate data from code
  • Applying strict schemas and validation to OpenAPI documents before generation
  • Restricting who and what can publish or modify API specifications
  • Reviewing generated artifacts before they enter builds or release pipelines
  • Running generation and downstream tooling with least privilege and limited access to secrets

These controls reduce the likelihood that a malicious specification can alter generated program behavior.

Mitigation generally focuses on treating OpenAPI documents as untrusted data and preventing their contents from becoming executable source structure.

Common defensive patterns include:

  • Serializing generated string values with context-appropriate, standards-compliant escaping
  • Using structured AST or template-generation mechanisms that separate data from code
  • Applying strict schemas and validation to OpenAPI documents before generation
  • Restricting who and what can publish or modify API specifications
  • Reviewing generated artifacts before they enter builds or release pipelines
  • Running generation and downstream tooling with least privilege and limited access to secrets

These controls reduce the likelihood that a malicious specification can alter generated program behavior.

How teams detect issues like this

Organizations can identify this class of issue through:

  • Static analysis for direct interpolation of specification values into JavaScript string literals
  • Code review checks for missing escaping or serialization at code-generation boundaries
  • Tests using delimiter-bearing and other adversarial metadata values to inspect generated source
  • CI policies that validate OpenAPI provenance and scan generated artifacts for unexpected executable constructs
  • Dependency and source review processes for generators that transform untrusted documents into code

Automated security review tools may help flag unsafe interpolation patterns, but generated output should also be inspected.

Organizations can identify this class of issue through:

  • Static analysis for direct interpolation of specification values into JavaScript string literals
  • Code review checks for missing escaping or serialization at code-generation boundaries
  • Tests using delimiter-bearing and other adversarial metadata values to inspect generated source
  • CI policies that validate OpenAPI provenance and scan generated artifacts for unexpected executable constructs
  • Dependency and source review processes for generators that transform untrusted documents into code

Automated security review tools may help flag unsafe interpolation patterns, but generated output should also be inspected.

Sources

SourceLink
github.comgithub.com/ferdikoomen/openapi-typescript-codegen
github.comgithub.com/ferdikoomen/openapi-typescript-codegen/blob/v0.31.0/src/templates/core/OpenAPI.hbs#L20-L23
github.comgithub.com/ferdikoomen/openapi-typescript-codegen/blob/v0.31.0/src/templates/exportService.hbs#L89-L110
github.comgithub.com/ferdikoomen/openapi-typescript-codegen/issues/2809
vulncheck.comvulncheck.com/advisories/openapi-typescript-codegen-through-0.31.0-code-injection-via-handlebars-templates

Frequently asked

questions

It can be, depending on how OpenAPI documents are obtained and processed. A remote attacker may influence execution if an application, build system, or service generates clients from attacker-controlled specifications and later uses the generated code.

The attacker generally needs control over, or an opportunity to modify, an OpenAPI document consumed by the generator. The resulting generated client must then be imported or executed for the injected behavior to take effect.

Keep specification values separate from executable source by using safe serialization or AST-based generation, and apply context-aware escaping wherever values are emitted into generated code.

Treat API specifications as untrusted input, enforce provenance and schema validation, test generated output with adversarial values, and require security review before generated artifacts are distributed or executed.

It can be, depending on how OpenAPI documents are obtained and processed. A remote attacker may influence execution if an application, build system, or service generates clients from attacker-controlled specifications and later uses the generated code.

The attacker generally needs control over, or an opportunity to modify, an OpenAPI document consumed by the generator. The resulting generated client must then be imported or executed for the injected behavior to take effect.

Keep specification values separate from executable source by using safe serialization or AST-based generation, and apply context-aware escaping wherever values are emitted into generated code.

Treat API specifications as untrusted input, enforce provenance and schema validation, test generated output with adversarial values, and require security review before generated artifacts are distributed or executed.

Find out what's already
exploitable in your codebase.