GHSA-2q42-4q24-7rgv: Path Traversal

Published Sep 8, 2026
·
Updated

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/TYPESPECPWNED/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 negativebefore=02dc7d056c2f773e56e2c1849947888b039f127ddd630c0bd76a5d7a9ca29cbd negativeafter=02dc7d056c2f773e56e2c1849947888b039f127ddd630c0bd76a5d7a9ca29cbd attackbefore=7a8067bc04e42a025de90fd7aff9be4df59f005d192f2116eecfb107d7bffd78 attackafter=2992b399c1573c9bd2130794f8554c4026bf425861f74e78b5d89ae0324b5e38 outsidefilehead=openapi: 3.0.0 insideattackfiles=

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.

Affected Software

2 affected components
npm/@typespec/compiler<=1.15.0
npm/@typespec/openapi3<=1.15.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade @typespec/compiler to a version that resolves this vulnerability.

    Fixed in 1.15.0
  2. Upgrade

    Upgrade @typespec/http to a version that resolves this vulnerability.

    Fixed in 1.15.0
  3. Upgrade

    Upgrade @typespec/openapi3 to a version that resolves this vulnerability.

    Fixed in 1.15.0
  4. Upgrade

    Upgrade @typespec/versioning to a version that resolves this vulnerability.

    Fixed in 0.85.0
  5. Configuration

    After interpolating all filename tokens (including {version} from @versioned enum members), resolve the completed destination against emitterOutputDir and reject any non-descendant using path-component-aware comparison; also reject or slugify absolute paths, path separators, and traversal components in spec-derived filename tokens to prevent out-of-directory YAML/JSON creation/overwrite.

    @typespec/openapi3 emitter (openapi.ts/emitter-utils.ts) output filename path validation/containment = path-component-aware containment check of interpolated destination against emitterOutputDir; reject or slugify absolute paths, path separators, and traversal components in spec-derived filename tokens

Event History

Sep 8, 2026
Advisory Published
via GitHub·09:31 PM
Data Sourced
via GitHub·09:31 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

Which package versions are confirmed affected?

The issue is confirmed on @typespec/compiler 1.15.0, @typespec/openapi3 1.15.0, @typespec/http 1.15.0, and @typespec/versioning 0.85.0. No patched version was identified.

2

What does an attacker need to provide to exploit this issue?

An attacker needs to supply a crafted declarative .tsp input containing a @versioned enum member with a malicious value. No executable TypeSpec extension or attacker-controlled JavaScript is required.

3

What is the practical filesystem impact?

The compiler can create or overwrite OpenAPI-formatted .yaml or .json files outside the configured emitterOutputDir. The resulting write is limited by the filesystem permissions of the compiler process.

4

Does configuring emitterOutputDir prevent writes outside that directory?

No. The completed output path reaches emitFile() without a containment check against emitterOutputDir, and parent directories may be created before the file is written.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203