Vulnerabilities in pkg:npm/@typespec/openapi3

PACKAGE
Advisory Summary

GHSA-2q42-4q24-7rgv is a HIGH (CVSS 7.1) openapi3 version value escapes `emitteroutputdir` vulnerability (CWE-73: External Control of File Name or Path) affecting @typespec/openapi3 libraries in the npm ecosystem. The issue involves openapi3 version value escapes `emitteroutputdir` and overwrites yaml/json outside the output tree. Remediation is available in the latest vendor maintenance releases.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/@typespec/openapi3

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/@typespec/openapi3. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-2q42-4q24-7rgv - HIGH OpenAPI3 version value escapes `emitterOutputDir` and overwrites YAML/JSON outside the output tree

GHSA-2q42-4q24-7rgv at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-2q42-4q24-7rgv
Severity HIGH
CVSS v3.1 Base Score 7.1
CWE Classification CWE-73: External Control of File Name or Path
Affected Product @typespec/openapi3
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.1

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

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity High (I:H)
Availability High (A:H)

How to Fix GHSA-2q42-4q24-7rgv

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

@typespec/openapi3 fixed: Latest secure release
npm install @typespec/openapi3@Latest secure release
@typespec/compiler fixed: Latest secure release
npm install @typespec/compiler@Latest secure release
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 @typespec/openapi3

How to Check if You Are Affected

To determine whether your Node.js application is affected by GHSA-2q42-4q24-7rgv, inspect your project dependencies using npm:

npm ls @typespec/openapi3

Analyze the terminal output to locate any version of @typespec/openapi3 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than the patched release), your application is affected.

Note: The npm ls @typespec/openapi3 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-73: External Control of File Name or Path, where the product allows user input to control or influence paths or file names that are used in filesystem operations. In @typespec/openapi3, 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 The `@typespec/openapi3` emitter retains the value of a `@versioned` enum member and interpolates it into the output filename as `{version}` without sanitizing path separators or traversal components. The completed path reaches the compiler's `emitFile()`, which creates the parent directory and writes the file without verifying containment under `emitterOutputDir`. A crafted declarative `.tsp` input can therefore create or overwrite an OpenAPI-formatted `.yaml` or `.json` file outside the configured output tree, subject to the compiler process's filesystem permissions. No executable TypeSpec extension or attacker-controlled JavaScript is required. ### Affected version Confirmed on: - `@typespec/compiler` `1.15.0` - `@typespec/openapi3` `1.15.0` - `@typespec/http` `1.15.0` - `@typespec/versioning` `0.85.0` - release tag commit `f30cd352f93997e04c75d48c7ace6947a1d5d07a` The critical `openapi.ts` and `emitter-utils.ts` blobs are unchanged on main commit `365ec52b50b82cd9e1e037de4c6fcd5de7e32e90` as checked on 2026-08-19. No patched version was identified. ### Root cause The value originates at `packages/openapi3/src/openapi.ts:592-608`: ```ts serviceRecord.versions.push({ service, version: snapshot.version!.value, document: document[0], diagnostics: document[1], }); ``` It is interpolated without path validation at `openapi.ts:629-641`: ```ts return interpolatePath(options.outputFile, { "openapi-version": specVersion, "service-name-if-multiple": multipleService ? getNamespaceFullName(service.type) : undefined, "service-name": getNamespaceFullName(service.type), "file-type": fileType, version, }); ``` The path reaches `emitFile()` at `openapi.ts:392-401`. The sink at `packages/compiler/src/core/emitter-utils.ts:29-39` performs no output-root containment check: ```ts const outputFolder = getDirectoryPath(options.path); await program.host.mkdirp(outputFolder); return await program.host.writeFile(options.path, content); ``` `resolvePath()` joins the template to `emitterOutputDir` before `{version}` is interpolated, so it does not see the attacker-controlled `..` components. ### Proof of concept The relevant input in `poc/main.tsp` is: ```tsp @versioned(Versions) namespace Svc; enum Versions { v1: "../../../../../../../../../../tmp/TYPESPEC_PWNED/pwn" } ``` Run from PowerShell: ```powershell cd poc .\run-revalidation.ps1 ``` The supplied Docker runner uses a digest-pinned Node base, a committed npm integrity lock, disabled runtime networking, a benign control, a 90-second timeout, and cleanup enforcement. Observed in the preserved identity-locked replay (`1/1` attack and `1/1` negative control): ```text negative_before=02dc7d056c2f773e56e2c1849947888b039f127ddd630c0bd76a5d7a9ca29cbd negative_after=02dc7d056c2f773e56e2c1849947888b039f127ddd630c0bd76a5d7a9ca29cbd attack_before=7a8067bc04e42a025de90fd7aff9be4df59f005d192f2116eecfb107d7bffd78 attack_after=2992b399c1573c9bd2130794f8554c4026bf425861f74e78b5d89ae0324b5e38 outside_file_head=openapi: 3.0.0 inside_attack_files= ``` The benign version preserved the outside canary. The crafted version replaced it with emitted OpenAPI content, and no attack output file remained under `tsp-output`. ### Impact and constraints Proven impact is out-of-directory YAML/JSON creation or overwrite. The attacker can influence the traversal, final basename, and many strings in the OpenAPI-structured content. The extension is constrained to the selected emitter format, content is not arbitrary bytes, and the target must be writable. This report demonstrates file corruption. Denial of service is a potential impact when a writable critical file is targeted. It does not claim file disclosure, arbitrary-byte write, deployment takeover, or code execution by a downstream consumer. ### Suggested remediation After every filename token has been interpolated, resolve the completed destination against `emitterOutputDir` and reject any non-descendant using path-component-aware comparison. Reject or slugify absolute paths, path separators, and traversal components in spec-derived filename tokens. Add regression cases for POSIX and Windows separators, absolute values, sibling-prefix paths, and benign semantic versions.

GHSA-2q42-4q24-7rgv Affected @typespec/openapi3 Versions

2 component(s)
Product / Package Ecosystem Affected Versions Fixed Version
@typespec/openapi3
npm
≤ 1.15.0
@typespec/compiler
npm
≤ 1.15.0

References

Frequently Asked Questions

What is GHSA-2q42-4q24-7rgv?
GHSA-2q42-4q24-7rgv is a security vulnerability in @typespec/openapi3 involving OpenAPI3 version value escapes `emitterOutputDir` and overwrites YAML/JSON outside the output tree under CWE-73: External Control of File Name or Path.
Which @typespec/openapi3 versions are affected?
Affected versions include releases prior to current release patches across affected packages: @typespec/openapi3, @typespec/compiler.
What version fixes GHSA-2q42-4q24-7rgv?
Upgrading to current release patches (or the latest patched release for your respective branch) resolves the vulnerability.
Is @typespec/openapi3 affected?
Yes, @typespec/openapi3 is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
Is @typespec/compiler affected?
Yes, @typespec/compiler is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
What is the CVSS score of GHSA-2q42-4q24-7rgv?
GHSA-2q42-4q24-7rgv has a CVSS v3.1 base score of 7.1 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H.
What CWE is associated with GHSA-2q42-4q24-7rgv?
GHSA-2q42-4q24-7rgv is classified under CWE-73: External Control of File Name or Path (The product allows user input to control or influence paths or file names that are used in filesystem operations.).
How can I check npm dependencies for GHSA-2q42-4q24-7rgv?
Run the dependency tree command: 'npm ls @typespec/openapi3'. 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-2q42-4q24-7rgv",
  "modified" : "2026-09-08T21:31:09Z",
  "published" : "2026-09-08T21:31:09Z",
  "aliases" : [ ],
  "summary" : "OpenAPI3 version value escapes `emitterOutputDir` and overwrites YAML/JSON outside the output tree",
  "details" : "### Summary\n\nThe `@typespec/openapi3` emitter retains the value of a `@versioned` enum member and interpolates it into the output filename as `{version}` without sanitizing path separators or traversal components. The completed path reaches the compiler's `emitFile()`, which creates the parent directory and writes the file without verifying containment under `emitterOutputDir`.\n\nA crafted declarative `.tsp` input can therefore create or overwrite an OpenAPI-formatted `.yaml` or `.json` file outside the configured output tree, subject to the compiler process's filesystem permissions. No executable TypeSpec extension or attacker-controlled JavaScript is required.\n\n### Affected version\n\nConfirmed on:\n\n- `@typespec/compiler` `1.15.0`\n- `@typespec/openapi3` `1.15.0`\n- `@typespec/http` `1.15.0`\n- `@typespec/versioning` `0.85.0`\n- release tag commit `f30cd352f93997e04c75d48c7ace6947a1d5d07a`\n\nThe critical `openapi.ts` and `emitter-utils.ts` blobs are unchanged on main commit `365ec52b50b82cd9e1e037de4c6fcd5de7e32e90` as checked on 2026-08-19. No patched version was identified.\n\n### Root cause\n\nThe value originates at `packages/openapi3/src/openapi.ts:592-608`:\n\n```ts\nserviceRecord.versions.push({\n  service,\n  version: snapshot.version!.value,\n  document: document[0],\n  diagnostics: document[1],\n});\n```\n\nIt is interpolated without path validation at `openapi.ts:629-641`:\n\n```ts\nreturn interpolatePath(options.outputFile, {\n  \"openapi-version\": specVersion,\n  \"service-name-if-multiple\": multipleService ? getNamespaceFullName(service.type) : undefined,\n  \"service-name\": getNamespaceFullName(service.type),\n  \"file-type\": fileType,\n  version,\n});\n```\n\nThe path reaches `emitFile()` at `openapi.ts:392-401`. The sink at `packages/compiler/src/core/emitter-utils.ts:29-39` performs no output-root containment check:\n\n```ts\nconst outputFolder = getDirectoryPath(options.path);\nawait program.host.mkdirp(outputFolder);\nreturn await program.host.writeFile(options.path, content);\n```\n\n`resolvePath()` joins the template to `emitterOutputDir` before `{version}` is interpolated, so it does not see the attacker-controlled `..` components.\n\n### Proof of concept\n\nThe relevant input in `poc/main.tsp` is:\n\n```tsp\n@versioned(Versions) namespace Svc;\nenum Versions { v1: \"../../../../../../../../../../tmp/TYPESPEC_PWNED/pwn\" }\n```\n\nRun from PowerShell:\n\n```powershell\ncd poc\n.\\run-revalidation.ps1\n```\n\nThe supplied Docker runner uses a digest-pinned Node base, a committed npm integrity lock, disabled runtime networking, a benign control, a 90-second timeout, and cleanup enforcement.\n\nObserved in the preserved identity-locked replay (`1/1` attack and `1/1` negative control):\n\n```text\nnegative_before=02dc7d056c2f773e56e2c1849947888b039f127ddd630c0bd76a5d7a9ca29cbd\nnegative_after=02dc7d056c2f773e56e2c1849947888b039f127ddd630c0bd76a5d7a9ca29cbd\nattack_before=7a8067bc04e42a025de90fd7aff9be4df59f005d192f2116eecfb107d7bffd78\nattack_after=2992b399c1573c9bd2130794f8554c4026bf425861f74e78b5d89ae0324b5e38\noutside_file_head=openapi: 3.0.0\ninside_attack_files=\n```\n\nThe benign version preserved the outside canary. The crafted version replaced it with emitted OpenAPI content, and no attack output file remained under `tsp-output`.\n\n### Impact and constraints\n\nProven impact is out-of-directory YAML/JSON creation or overwrite. The attacker can influence the traversal, final basename, and many strings in the OpenAPI-structured content. The extension is constrained to the selected emitter format, content is not arbitrary bytes, and the target must be writable.\n\nThis report demonstrates file corruption. Denial of service is a potential impact when a writable critical file is targeted. It does not claim file disclosure, arbitrary-byte write, deployment takeover, or code execution by a downstream consumer.\n\n### Suggested remediation\n\nAfter every filename token has been interpolated, resolve the completed destination against `emitterOutputDir` and reject any non-descendant using path-component-aware comparison. Reject or slugify absolute paths, path separators, and traversal components in spec-derived filename tokens. Add regression cases for POSIX and Windows separators, absolute values, sibling-prefix paths, and benign semantic versions.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@typespec/openapi3"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "1.15.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@typespec/compiler"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "1.15.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/microsoft/typespec/security/advisories/GHSA-2q42-4q24-7rgv"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/microsoft/typespec/pull/11777"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/microsoft/typespec/commit/e0f67bdf3c5a0875dfa98b475648af37caac71a6"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/microsoft/typespec"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22", "CWE-73" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-09-08T21:31:09Z",
    "nvd_published_at" : null
  }
}