/

CVE-2026-54661

Severity:

HIGH RISK

(8.3)

Code Injection (CWE-94) in Swagger TypeScript API

CVE-2026-54661

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 templates can embed unescaped OpenAPI server URLs directly into generated Axios HttpClient constructors, enabling code injection.

When developers consume attacker-controlled or untrusted OpenAPI specifications, the resulting generated client code may execute arbitrary JavaScript at construction time.

swagger-typescript-api templates can embed unescaped OpenAPI server URLs directly into generated Axios HttpClient constructors, enabling code injection.

When developers consume attacker-controlled or untrusted OpenAPI specifications, the resulting generated client code may execute arbitrary JavaScript at construction time.

Affected context

This vulnerability appears in projects that use swagger-typescript-api to generate TypeScript clients from OpenAPI documents, specifically when:

  • The Axios-based HTTP client template is selected or used by default
  • OpenAPI servers[0].url values are taken directly from untrusted or externally supplied specifications
  • Generated code is compiled and executed without reviewing or sanitizing the interpolated server URL

It is most relevant in environments where OpenAPI specs can be influenced by third parties, such as shared API registries, dynamic spec generation, or multi-tenant documentation systems.

This vulnerability appears in projects that use swagger-typescript-api to generate TypeScript clients from OpenAPI documents, specifically when:

  • The Axios-based HTTP client template is selected or used by default
  • OpenAPI servers[0].url values are taken directly from untrusted or externally supplied specifications
  • Generated code is compiled and executed without reviewing or sanitizing the interpolated server URL

It is most relevant in environments where OpenAPI specs can be influenced by third parties, such as shared API registries, dynamic spec generation, or multi-tenant documentation systems.

Exploit preconditions

  • Attack surface: The code generation pipeline that consumes OpenAPI specifications.
  • Required access: Ability to provide or modify an OpenAPI spec used by swagger-typescript-api (e.g., control over servers[0].url).
  • Trigger point: Construction of a generated HttpClient or Api instance in application code, which executes the injected JavaScript.
  • Why exploitation is possible: The Axios HttpClient EJS template interpolates servers[0].url directly into TypeScript source without escaping or validation, allowing malicious content to break out of string context and inject executable code.
  • Attack surface: The code generation pipeline that consumes OpenAPI specifications.
  • Required access: Ability to provide or modify an OpenAPI spec used by swagger-typescript-api (e.g., control over servers[0].url).
  • Trigger point: Construction of a generated HttpClient or Api instance in application code, which executes the injected JavaScript.
  • Why exploitation is possible: The Axios HttpClient EJS template interpolates servers[0].url directly into TypeScript source without escaping or validation, allowing malicious content to break out of string context and inject executable code.

Why this happens

The underlying bug stems from treating data originating from an OpenAPI document as trusted code in a template-driven generation process.

In the vulnerable Axios client template, servers[0].url is interpolated without escaping or confinement to a safe literal string, enabling crafted values to alter the generated TypeScript syntax and inject arbitrary JavaScript.

This pattern maps to CWE-94 (Improper Control of Generation of Code), combined with CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component) and CWE-1336 (Improper Neutralization of Script-Related HTML Tags in a Web Page), because spec fields are not neutralized before being embedded in source code that will later be executed.

The underlying bug stems from treating data originating from an OpenAPI document as trusted code in a template-driven generation process.

In the vulnerable Axios client template, servers[0].url is interpolated without escaping or confinement to a safe literal string, enabling crafted values to alter the generated TypeScript syntax and inject arbitrary JavaScript.

This pattern maps to CWE-94 (Improper Control of Generation of Code), combined with CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component) and CWE-1336 (Improper Neutralization of Script-Related HTML Tags in a Web Page), because spec fields are not neutralized before being embedded in source code that will later be executed.

Potential impact

  • Generated clients may execute attacker-controlled JavaScript during object construction.
  • Attackers could access or exfiltrate sensitive data handled by the client, such as tokens or headers.
  • Malicious code can tamper with outgoing requests, altering endpoints, parameters, or authentication behavior.
  • The broader application runtime may be compromised if generated clients run in privileged or trusted contexts.
  • Generated clients may execute attacker-controlled JavaScript during object construction.
  • Attackers could access or exfiltrate sensitive data handled by the client, such as tokens or headers.
  • Malicious code can tamper with outgoing requests, altering endpoints, parameters, or authentication behavior.
  • The broader application runtime may be compromised if generated clients run in privileged or trusted contexts.

General mitigation guidance

Effective mitigation focuses on treating specification-derived values as untrusted input and preventing them from becoming executable code.

General defensive patterns include:

  • Escaping or safely encoding all OpenAPI fields before interpolating into templates so they remain data within string literals.
  • Constraining servers configuration to validated, well-formed URLs from trusted sources rather than arbitrary spec content.
  • Separating configuration data (such as base URLs) from generated code by providing them at runtime via environment variables or strongly typed configuration objects.
  • Applying least privilege principles to any code that consumes generated clients, so a compromised client has limited impact.
  • Designing templates so that dynamic fields cannot alter the surrounding syntax or introduce new statements, for example by using strict string concatenation and avoiding direct raw insertion into executable contexts.

Effective mitigation focuses on treating specification-derived values as untrusted input and preventing them from becoming executable code.

General defensive patterns include:

  • Escaping or safely encoding all OpenAPI fields before interpolating into templates so they remain data within string literals.
  • Constraining servers configuration to validated, well-formed URLs from trusted sources rather than arbitrary spec content.
  • Separating configuration data (such as base URLs) from generated code by providing them at runtime via environment variables or strongly typed configuration objects.
  • Applying least privilege principles to any code that consumes generated clients, so a compromised client has limited impact.
  • Designing templates so that dynamic fields cannot alter the surrounding syntax or introduce new statements, for example by using strict string concatenation and avoiding direct raw insertion into executable contexts.

How teams detect issues like this

Organizations can identify similar vulnerabilities through:

  • Static analysis rules that flag direct template interpolation of untrusted inputs into executable code segments or constructors.
  • Code review practices focused on code-generation templates, ensuring that external specification fields are always escaped or validated.
  • Build-time checks that scan generated sources for unexpected tokens, statements, or non-URL content where only configuration values should appear.
  • Policy-based controls requiring that OpenAPI documents used for generation originate from vetted repositories and pass schema, format, and sanitation checks before use.
  • Integrating automated code review tools to inspect both templates and generated output for code injection patterns.

Organizations can identify similar vulnerabilities through:

  • Static analysis rules that flag direct template interpolation of untrusted inputs into executable code segments or constructors.
  • Code review practices focused on code-generation templates, ensuring that external specification fields are always escaped or validated.
  • Build-time checks that scan generated sources for unexpected tokens, statements, or non-URL content where only configuration values should appear.
  • Policy-based controls requiring that OpenAPI documents used for generation originate from vetted repositories and pass schema, format, and sanitation checks before use.
  • Integrating automated code review tools to inspect both templates and generated output for code injection patterns.

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-38c3-wv3c-v3xj

Frequently asked

questions

It can be, if OpenAPI specifications are obtained from remote or multi-tenant sources that an attacker can influence. Once a malicious spec is consumed by swagger-typescript-api and the generated client is built and run, arbitrary code can execute in the client's environment.

An attacker needs the ability to supply or modify the OpenAPI specification used for client generation, specifically controlling fields like servers[0].url. This could be direct write access to the spec, control over a spec publishing pipeline, or influence over a shared documentation endpoint.

The most robust fix is to ensure that all spec-derived values are treated strictly as data: escape and validate them before template interpolation, and avoid generating executable logic directly from specification fields. Keeping base URLs and similar configuration outside of the generated code and providing them at runtime from trusted configuration is a strong defensive pattern.

Establish clear trust boundaries around specifications and other inputs to generators, enforce encoding and validation for all dynamic template fields, and review templates as carefully as application code. Incorporate automated checks for code injection patterns in both templates and generated output, and prefer generation designs where untrusted inputs cannot change syntax or control flow.

It can be, if OpenAPI specifications are obtained from remote or multi-tenant sources that an attacker can influence. Once a malicious spec is consumed by swagger-typescript-api and the generated client is built and run, arbitrary code can execute in the client's environment.

An attacker needs the ability to supply or modify the OpenAPI specification used for client generation, specifically controlling fields like servers[0].url. This could be direct write access to the spec, control over a spec publishing pipeline, or influence over a shared documentation endpoint.

The most robust fix is to ensure that all spec-derived values are treated strictly as data: escape and validate them before template interpolation, and avoid generating executable logic directly from specification fields. Keeping base URLs and similar configuration outside of the generated code and providing them at runtime from trusted configuration is a strong defensive pattern.

Establish clear trust boundaries around specifications and other inputs to generators, enforce encoding and validation for all dynamic template fields, and review templates as carefully as application code. Incorporate automated checks for code injection patterns in both templates and generated output, and prefer generation designs where untrusted inputs cannot change syntax or control flow.

Find out what's already
exploitable in your codebase.