Skip to content

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

High severity GitHub Reviewed Published Aug 28, 2026 in microsoft/typespec • Updated Sep 8, 2026

Package

npm @typespec/compiler (npm)

Affected versions

<= 1.15.0

Patched versions

None
npm @typespec/openapi3 (npm)
<= 1.15.0
None

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:

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.

References

@timotheeguerin timotheeguerin published to microsoft/typespec Aug 28, 2026
Published to the GitHub Advisory Database Sep 8, 2026
Reviewed Sep 8, 2026
Last updated Sep 8, 2026

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
None
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H

EPSS score

Weaknesses

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. Learn more on MITRE.

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. Learn more on MITRE.

CVE ID

No known CVE

GHSA ID

GHSA-2q42-4q24-7rgv

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.