/

CVE-2026-88899

Severity:

CRITICAL RISK

(9.8)

External Control of File Name or Path (CWE-73) in OpenCode

CVE-2026-88899

Deferred

Vulnerability type

Category:

External Control of File Name or Path

CWE:

CWE-73

Impact:

Unauthorized File Operations

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

OpenCode versions before 0.31.0 do not properly validate the x-opencode-directory request header used by the /api/opencode proxy endpoint. A remote attacker may provide an arbitrary directory path, causing file operations to occur outside the intended project root when the endpoint is reachable.

Affected context

The vulnerability occurs in deployments that expose the /api/opencode proxy endpoint and use the x-opencode-directory header to select or resolve a working directory. Risk increases when the header is accepted from untrusted clients without canonicalization, boundary checks, or enforcement that the resolved path remains within the configured project root.

Exploit preconditions

  • Attack surface: Network-accessible /api/opencode proxy endpoint
  • Required access: Ability to send requests to the endpoint; authentication requirements depend on deployment configuration
  • Trigger point: Processing of the x-opencode-directory request header
  • Why exploitation is possible: Insufficient validation allows attacker-controlled paths to influence file-operation targets outside the permitted project directory

Why this happens

The underlying bug is insufficient validation of an externally controlled path before it is used in filesystem operations. This maps to CWE-73: External Control of File Name or Path, where request data influences a filename or directory without reliably enforcing an approved path boundary, canonical form, or allowed location.

Potential impact

  • Unauthorized file operations outside the project root
  • Exposure, modification, or deletion of files accessible to the service
  • Tampering with project data or runtime configuration
  • Possible compromise of dependent workflows if modified files are later trusted or executed
  • Broader host impact if the service has excessive filesystem privileges

General mitigation guidance

Mitigation generally focuses on removing direct trust in client-supplied paths and enforcing a secure filesystem boundary.

Common defensive patterns include:

  • Resolve paths against a fixed trusted root and verify the canonical result remains within that root
  • Prefer server-side identifiers or allowlisted directory mappings over raw path headers
  • Reject absolute paths, traversal components, ambiguous encodings, and symlink escapes where appropriate
  • Apply consistent validation before every file operation rather than only at the request boundary
  • Run the service with the least filesystem privilege necessary
  • Use read-only mounts and isolated workspaces when write access is not required
  • Avoid exposing the proxy endpoint beyond trusted network boundaries

How teams detect issues like this

Organizations can identify this class of issue through:

  • Static analysis rules that trace request headers or parameters into filesystem APIs
  • Code review checks for path concatenation without canonicalization and root-boundary verification
  • Tests covering absolute paths, traversal sequences, symlinks, encoded separators, and platform-specific path formats
  • Runtime monitoring for file access outside approved project directories
  • Gateway policies that restrict or remove client-controlled directory headers
  • Automated security review tools that flag externally controlled paths reaching file operations

Sources

SourceLink
github.comgithub.com/knowns-dev/knowns/blob/v0.30.0/internal/server/server.go#L1283-L1296
github.comgithub.com/knowns-dev/knowns/commit/37db0561b37b48b8bd035a417d7f1da6258ae657
github.comgithub.com/knowns-dev/knowns/releases/tag/v0.31.0
github.comgithub.com/knowns-dev/knowns/security/advisories/GHSA-9h2q-r9fh-f98w
vulncheck.comvulncheck.com/advisories/knowns-before-0.31.0-external-control-of-agent-working-directory-via-x-opencode-directory-header

Frequently asked

questions

Yes, when the /api/opencode endpoint is network-accessible and accepts attacker-controlled requests. The practical scope also depends on authentication, authorization, and network exposure.

The attacker needs the ability to send requests to the affected proxy endpoint. Whether an account or other authorization is required depends on the deployment's access controls.

Treat the directory header as untrusted input, resolve paths under a trusted server-side root, and reject any canonical path that escapes that root. An allowlist of server-defined directory identifiers is safer than accepting arbitrary paths.

Review all request-to-filesystem data flows, test path-boundary enforcement across operating systems, minimize service filesystem privileges, and monitor for access outside approved directories.

Find out what's already
exploitable in your codebase.