/

CVE-2026-54666

Severity:

HIGH RISK

(8.3)

Code Injection (CWE-94) in swagger-typescript-api

CVE-2026-54666

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-74, CWE-94, CWE-1336

Impact:

Arbitrary Code Execution in Generated Client Code

Severity:

HIGH RISK

(8.3)

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

swagger-typescript-api improperly injects attacker-controlled OpenAPI path strings into JavaScript template literals when generating client methods, without escaping interpolation syntax.

If an API specification contains a path with ${...}, arbitrary JavaScript can execute when the generated client method runs, enabling high-impact code injection in consuming applications.

swagger-typescript-api improperly injects attacker-controlled OpenAPI path strings into JavaScript template literals when generating client methods, without escaping interpolation syntax.

If an API specification contains a path with ${...}, arbitrary JavaScript can execute when the generated client method runs, enabling high-impact code injection in consuming applications.

Affected context

This vulnerability affects projects that:

  • Use swagger-typescript-api to generate TypeScript API clients for Fetch or Axios
  • Consume OpenAPI specifications that may include untrusted or externally supplied path definitions
  • Compile and run the generated client code in production or development environments

The issue appears in the route name handling logic where OpenAPI path keys are transformed and inserted into JavaScript template literals in EJS templates without proper escaping of ${...} sequences.

This vulnerability affects projects that:

  • Use swagger-typescript-api to generate TypeScript API clients for Fetch or Axios
  • Consume OpenAPI specifications that may include untrusted or externally supplied path definitions
  • Compile and run the generated client code in production or development environments

The issue appears in the route name handling logic where OpenAPI path keys are transformed and inserted into JavaScript template literals in EJS templates without proper escaping of ${...} sequences.

Exploit preconditions

  • Attack surface: The OpenAPI specification file or definition used as input to swagger-typescript-api.
  • Required access: Ability to add or modify paths in the OpenAPI spec (e.g., via compromised spec repository, malicious upstream service definition, or supply-chain manipulation).
  • Trigger point: Execution of a generated client method whose name or internal logic derives from a path containing ${...}.
  • Why exploitation is possible: Path keys are passed through parseRouteName into EJS templates and emitted as JavaScript template literals without escaping interpolation, turning crafted spec content into executable code inside the generated client.
  • Attack surface: The OpenAPI specification file or definition used as input to swagger-typescript-api.
  • Required access: Ability to add or modify paths in the OpenAPI spec (e.g., via compromised spec repository, malicious upstream service definition, or supply-chain manipulation).
  • Trigger point: Execution of a generated client method whose name or internal logic derives from a path containing ${...}.
  • Why exploitation is possible: Path keys are passed through parseRouteName into EJS templates and emitted as JavaScript template literals without escaping interpolation, turning crafted spec content into executable code inside the generated client.

Why this happens

The underlying bug is a failure to treat OpenAPI specification content as untrusted data when embedding it into source code.

In swagger-typescript-api, path strings are fed into EJS templates that output JavaScript/TypeScript methods using template literals. Because ${...} sequences in the path are not escaped or sanitized, they are interpreted as JavaScript expressions at runtime.

This maps to CWE-94: Code Injection, where user-controlled input is incorporated into executable code; CWE-74: Improper Neutralization of Data within a Different Syntax Region, because data crosses from specification text into JavaScript syntax; and CWE-1336: Improper Neutralization for Alternate Syntax, as template literal semantics are not correctly accounted for when generating code.

The underlying bug is a failure to treat OpenAPI specification content as untrusted data when embedding it into source code.

In swagger-typescript-api, path strings are fed into EJS templates that output JavaScript/TypeScript methods using template literals. Because ${...} sequences in the path are not escaped or sanitized, they are interpreted as JavaScript expressions at runtime.

This maps to CWE-94: Code Injection, where user-controlled input is incorporated into executable code; CWE-74: Improper Neutralization of Data within a Different Syntax Region, because data crosses from specification text into JavaScript syntax; and CWE-1336: Improper Neutralization for Alternate Syntax, as template literal semantics are not correctly accounted for when generating code.

Potential impact

  • Generated client methods may execute arbitrary JavaScript provided via the OpenAPI spec.
  • Attackers could access application secrets, environment variables, or sensitive data available to the client runtime.
  • Malicious code can alter request parameters or responses, enabling data exfiltration or tampering.
  • The compromised client library can serve as an entry point for broader application compromise or supply-chain attacks.
  • Generated client methods may execute arbitrary JavaScript provided via the OpenAPI spec.
  • Attackers could access application secrets, environment variables, or sensitive data available to the client runtime.
  • Malicious code can alter request parameters or responses, enabling data exfiltration or tampering.
  • The compromised client library can serve as an entry point for broader application compromise or supply-chain attacks.

General mitigation guidance

Effective mitigation focuses on separating data from code during client generation and enforcing strict neutralization of specification content:

  • Treat all OpenAPI paths, operation IDs, and descriptions as untrusted data when embedding into generated code.
  • Escape or sanitize characters that have special meaning in JavaScript template literals, particularly ${ and backticks, before inserting them into source templates.
  • Use code-generation patterns that avoid executing or dynamically evaluating generated strings at runtime, preferring static methods and safe string concatenation.
  • Constrain trust boundaries by limiting who can modify OpenAPI specifications and by reviewing changes to spec files with the same rigor as code changes.
  • Apply least-privilege principles to environments where generated clients run so that, even if injection occurs, the runtime has reduced access to sensitive resources.

Effective mitigation focuses on separating data from code during client generation and enforcing strict neutralization of specification content:

  • Treat all OpenAPI paths, operation IDs, and descriptions as untrusted data when embedding into generated code.
  • Escape or sanitize characters that have special meaning in JavaScript template literals, particularly ${ and backticks, before inserting them into source templates.
  • Use code-generation patterns that avoid executing or dynamically evaluating generated strings at runtime, preferring static methods and safe string concatenation.
  • Constrain trust boundaries by limiting who can modify OpenAPI specifications and by reviewing changes to spec files with the same rigor as code changes.
  • Apply least-privilege principles to environments where generated clients run so that, even if injection occurs, the runtime has reduced access to sensitive resources.

How teams detect issues like this

Teams can identify similar vulnerabilities using:

  • Static analysis rules or custom linters that flag code-generation paths where template literals or string interpolation directly incorporate untrusted specification content.
  • Code review practices that treat EJS or other templating files as security-sensitive, checking for proper escaping functions around all spec-derived values.
  • Repository policies that require security review for changes to OpenAPI specs, generator templates, and parsing utilities like parseRouteName.
  • Automated build-time checks that scan generated output for ${ sequences originating from spec content, indicating potential injection vectors.

Teams can identify similar vulnerabilities using:

  • Static analysis rules or custom linters that flag code-generation paths where template literals or string interpolation directly incorporate untrusted specification content.
  • Code review practices that treat EJS or other templating files as security-sensitive, checking for proper escaping functions around all spec-derived values.
  • Repository policies that require security review for changes to OpenAPI specs, generator templates, and parsing utilities like parseRouteName.
  • Automated build-time checks that scan generated output for ${ sequences originating from spec content, indicating potential injection vectors.

Sources

SourceLink
github.comgithub.com/acacode/swagger-typescript-api/commit/306d59acb8ffbb00f953f807b97234b21f51d9de
github.comgithub.com/acacode/swagger-typescript-api/pull/1779
github.comgithub.com/acacode/swagger-typescript-api/releases/tag/v13.12.2
github.comgithub.com/acacode/swagger-typescript-api/security/advisories/GHSA-w284-33mx-6g9v

Frequently asked

questions

Exploitability depends on who controls the OpenAPI specification. If an attacker can modify the spec used to generate clients—through a compromised repository, malicious upstream API provider, or tampered artifact—they can craft paths that inject code into consumer applications.

An attacker needs the ability to influence or supply the OpenAPI specification consumed by swagger-typescript-api. They do not need direct access to the application codebase if the spec is trusted and automatically used for client generation.

Ensure all spec-derived strings are treated as data, not code, by escaping or sanitizing template-literal metacharacters before embedding them into generated source. In code generators, centralize escaping routines and avoid patterns where arbitrary spec content can be evaluated or interpolated as JavaScript.

Adopt secure-by-design conventions for code generation: define strict contracts for which spec fields may influence identifiers, always escape content crossing syntax boundaries, and enforce security-focused review on templating logic. Combine this with governance over specification sources and continuous static analysis of generators and their outputs.

Exploitability depends on who controls the OpenAPI specification. If an attacker can modify the spec used to generate clients—through a compromised repository, malicious upstream API provider, or tampered artifact—they can craft paths that inject code into consumer applications.

An attacker needs the ability to influence or supply the OpenAPI specification consumed by swagger-typescript-api. They do not need direct access to the application codebase if the spec is trusted and automatically used for client generation.

Ensure all spec-derived strings are treated as data, not code, by escaping or sanitizing template-literal metacharacters before embedding them into generated source. In code generators, centralize escaping routines and avoid patterns where arbitrary spec content can be evaluated or interpolated as JavaScript.

Adopt secure-by-design conventions for code generation: define strict contracts for which spec fields may influence identifiers, always escape content crossing syntax boundaries, and enforce security-focused review on templating logic. Combine this with governance over specification sources and continuous static analysis of generators and their outputs.

Find out what's already
exploitable in your codebase.