# GHSA-2q42-4q24-7rgv: OpenAPI3 version value escapes `emitterOutputDir` and overwrites YAML/JSON outside the output tree

> A path traversal vulnerability in the TypeSpec OpenAPI3 emitter allows attackers to overwrite files outside the output directory via crafted version strings.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** No
- **Published:** 8 Sep 2026

## What is GHSA-2q42-4q24-7rgv?

GHSA-2q42-4q24-7rgv is a path traversal vulnerability in @typespec/compiler, published on 8 Sep 2026. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

### Official description

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

## Which versions are affected by GHSA-2q42-4q24-7rgv?

4 open source packages ship an affected version, including @typespec/compiler and @typespec/openapi3.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `@typespec/compiler` | npm | All versions to 1.15.0 | None |
| `@typespec/compiler` | npm | All versions to 1.15.0 | None |
| `@typespec/openapi3` | npm | All versions to 1.15.0 | None |
| `@typespec/openapi3` | npm | All versions to 1.15.0 | None |

## How do I fix GHSA-2q42-4q24-7rgv?

No fix has been published for GHSA-2q42-4q24-7rgv yet. Limit exposure of the affected software until one is available.

## Is GHSA-2q42-4q24-7rgv being exploited?

There is no known exploitation of GHSA-2q42-4q24-7rgv in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-2q42-4q24-7rgv and fix it if it is affected.

What it is: GHSA-2q42-4q24-7rgv is a path traversal vulnerability in @typespec/compiler, published on 8 Sep 2026. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-2q42-4q24-7rgv in the wild and no public exploit code.

Affected packages and fixed versions:
- @typespec/compiler (npm): affected all versions up to 1.15.0; no fix listed
- @typespec/compiler (npm): affected all versions up to 1.15.0; no fix listed
- @typespec/openapi3 (npm): affected all versions up to 1.15.0; no fix listed
- @typespec/openapi3 (npm): affected all versions up to 1.15.0; no fix listed

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-2q42-4q24-7rgv/ (Markdown: https://insights.sbomify.com/GHSA-2q42-4q24-7rgv/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-2q42-4q24-7rgv

---
From sbomify Insights: https://insights.sbomify.com/GHSA-2q42-4q24-7rgv/
Summaries are generated and may contain mistakes; the official description above is the record.
