nday
GHSA-2q42-4q24-7rgv

OpenAPI3 version value escapes `emitterOutputDir` and overwrites YAML/JSON outside the output tree

披露后第 84 天有补丁记录。已有补丁记录,修复版本是 @typespec/openapi3 1.16.0、@typespec/compiler 1.16.0。四个 PoC 来源都还没有收录。尚未列入 CISA KEV。

标签 漏洞类型path traversal 攻击途径本地无需认证 软件包生态npm
这些标签的依据

这些标签由 nday 按固定规则从下列事实自动推导,不是 NVD、编号分配方或其他来源给出的。全部标签和规则见 ~/tags。

path traversal
CWE-22(来源:GitHub 公告 GHSA-2q42-4q24-7rgv)CWE-73(来源:GitHub 公告 GHSA-2q42-4q24-7rgv)
本地
GitHub 公告 GHSA-2q42-4q24-7rgv 给出的 CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H(CVSS 3.1)中的 AV:L
无需认证
GitHub 公告 GHSA-2q42-4q24-7rgv 给出的 CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H(CVSS 3.1)中的 PR:N
npm
GHSA-2q42-4q24-7rgv:npm 包 @typespec/compiler、@typespec/openapi3
当前阶段
PAT
披露
披露到补丁
T+84d
CVSS
7.1 HIGH v3.1

生命周期

横轴 UTC;点=精确到分钟,宽条=仅日期,空心=未知或推定。
时间未知
DIS披露
09-08T21:31Z
PAT补丁
12-01T15:01Z
ANA分析
尚无记录
POCPoC
尚无记录
ITW在野
尚无记录
KEVKEV
尚无记录

摘要

### 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:

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:

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:

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:

@versioned(Versions) namespace Svc;
enum Versions { v1: "../../../../../../../../../../tmp/TYPESPEC_PWNED/pwn" }

Run from 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):

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.

以上是 GitHub 安全公告 GHSA-2q42-4q24-7rgv 中的原文,未经改写。

利用条件

按 CVSS 向量说明攻击需要的条件。
攻击途径 AV:L
本地:需要本地或 SSH 会话,或诱使用户在本机上操作
攻击复杂度 AC:L
低:不依赖特殊条件,攻击者可预期重复成功
所需权限 PR:N
无:不需要账号或授权
用户交互 UI:R
需要:须有用户执行某个操作,例如打开文件或点击链接

CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H

CVSS 3.1 向量,来自 GitHub 安全公告 GHSA-2q42-4q24-7rgv。

事件记录

+DIS披露

ghsa 报告了披露事件。

来源 ghsa · 本站 实时观测 · 原始记录
{
  "id": 564105,
  "type": "disclosed",
  "source": "ghsa",
  "url": "https://github.com/advisories/GHSA-2q42-4q24-7rgv",
  "occurred_at": "2026-09-08T21:31:09Z",
  "observed_at": "2026-12-01T15:01:52.464415Z",
  "is_backfill": false,
  "dedupe_key": "GHSA-2q42-4q24-7rgv",
  "detail": {
    "state": "PUBLISHED",
    "ghsa_id": "GHSA-2q42-4q24-7rgv",
    "withdrawn_at": null
  }
}
来源未给时间,本站实时观测
+PAT补丁发布

公告给出修复版本 @typespec/openapi3 1.16.0、@typespec/compiler 1.16.0。公告附有修复提交。公告本身发布于 ,补丁实际发布时间没有记录。

来源 ghsa · 本站 实时观测 · 原始记录
{
  "id": 564106,
  "type": "patch_released",
  "source": "ghsa",
  "url": "https://github.com/advisories/GHSA-2q42-4q24-7rgv",
  "occurred_at": null,
  "observed_at": "2026-12-01T15:01:52.464415Z",
  "is_backfill": false,
  "dedupe_key": "GHSA-2q42-4q24-7rgv",
  "detail": {
    "cvss": {
      "cvss_v3": {
        "score": 7.1,
        "vector_string": "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H"
      },
      "cvss_v4": {
        "score": 0.0,
        "vector_string": null
      }
    },
    "cwes": [
      {
        "name": "Improper Limitation of a Pathname to a Restricted Directory",
        "cwe_id": "CWE-22"
      },
      {
        "name": "External Control of File Name or Path",
        "cwe_id": "CWE-73"
      }
    ],
    "ghsa_id": "GHSA-2q42-4q24-7rgv",
    "packages": [
      {
        "name": "@typespec/openapi3",
        "ecosystem": "npm",
        "first_patched_version": "1.16.0",
        "vulnerable_version_range": "<= 1.15.0"
      },
      {
        "name": "@typespec/compiler",
        "ecosystem": "npm",
        "first_patched_version": "1.16.0",
        "vulnerable_version_range": "<= 1.15.0"
      }
    ],
    "severity": "high",
    "references": [
      "https://github.com/microsoft/typespec/security/advisories/GHSA-2q42-4q24-7rgv",
      "https://github.com/microsoft/typespec/pull/11777",
      "https://github.com/microsoft/typespec/commit/e0f67bdf3c5a0875dfa98b475648af37caac71a6",
      "https://github.com/microsoft/typespec/releases/tag/[email protected]",
      "https://github.com/advisories/GHSA-2q42-4q24-7rgv"
    ],
    "fix_commit_urls": [
      "https://github.com/microsoft/typespec/pull/11777",
      "https://github.com/microsoft/typespec/commit/e0f67bdf3c5a0875dfa98b475648af37caac71a6"
    ],
    "github_reviewed_at": "2026-09-08T21:31:09Z",
    "advisory_updated_at": "2026-12-01T14:35:05Z",
    "source_code_location": "https://github.com/microsoft/typespec",
    "advisory_published_at": "2026-09-08T21:31:09Z"
  }
}

纠错

报告错误或缺失

页面有误或缺失?告诉编辑;采纳后在本页修订记录公开说明,上游数据不会被改动。

讨论

0 条评论

还没有评论。