/

CVE-2026-86541

Severity:

HIGH RISK

(8.3)

Path Traversal (CWE-22) in knowns Code Replacement

CVE-2026-86541

Deferred

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Overwrite and Potential Code Execution

Severity:

HIGH RISK

(8.3)

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

A path traversal vulnerability in knowns' handleCodeReplace() function allows attacker-controlled paths to escape the intended project directory. If an attacker can reach the affected file-writing operation, they may overwrite sensitive files, including shell startup scripts or SSH configuration.

Affected context

The vulnerability occurs in knowns versions that use handleCodeReplace() to write generated or replaced content to disk without sufficiently restricting the destination path. It becomes risky when attacker-controlled input can influence that path and the process has write access outside the project root.

Exploit preconditions

  • Attack surface: The file-writing workflow that invokes handleCodeReplace()
  • Required access: Ability to provide or influence the destination path and content
  • Trigger point: Processing a code-replacement request or operation
  • Why exploitation is possible: Absolute paths and traversal sequences may escape the intended project directory before the write is performed

Why this happens

The underlying bug is improper neutralization of path elements used to construct a filesystem destination. When absolute paths or relative paths containing traversal sequences are accepted without canonicalization and boundary enforcement, the operation can write outside its intended root. This maps to CWE-22, Path Traversal.

Potential impact

Attackers may overwrite arbitrary files that are writable by the application process.; Attackers could modify shell startup scripts or other files that execute code in a user context.; Attackers may alter SSH configuration or credentials-related files, depending on permissions.; The application or host could experience integrity loss, persistence, or code execution.

General mitigation guidance

Mitigation generally focuses on making file destinations safe by default and

reducing trust in user-supplied paths.

Common defensive patterns include:

  • Resolve candidate paths against a fixed permitted root and verify that the canonical result remains within that root.
  • Reject absolute paths and traversal components when they are not required by the workflow.
  • Prefer server-generated file identifiers or constrained relative names over caller-supplied filesystem paths.
  • Apply strict allowlists for permitted directories, filenames, and file types.
  • Use least-privilege service accounts and limit write permissions to the minimum required workspace.
  • Separate generated content from executable, credential, and SSH-related locations.
  • Treat path validation as a security control performed before any file is opened or created.

How teams detect issues like this

Detection approaches commonly include:

  • Static analysis rules for filesystem writes that use request data or other untrusted values in path construction.
  • Code review checks for missing canonicalization, root-boundary validation, or rejection of absolute paths.
  • Tests covering traversal sequences, absolute paths, symbolic-link boundaries, and platform-specific path formats.
  • Runtime policies that restrict the process to an approved workspace and alert on writes outside it.
  • File-integrity monitoring for unexpected changes to startup scripts, SSH configuration, and other sensitive paths.

Automated security review tools may help identify dangerous path joins and unvalidated file destinations.

Sources

SourceLink
github.comgithub.com/knowns-dev/knowns/blob/v0.29.1/internal/mcp/handlers/code.go#L588-L646
github.comgithub.com/knowns-dev/knowns/commit/a2c98fc5c313463576c9348beeec6a74ddd7333b
github.comgithub.com/knowns-dev/knowns/releases/tag/v0.30.0
github.comgithub.com/knowns-dev/knowns/security/advisories/GHSA-f539-xgc6-xw7q
vulncheck.comvulncheck.com/advisories/knowns-before-0.30.0-path-traversal-via-code-replace-mcp-action

Frequently asked

questions

It can be remotely exploitable when an exposed application workflow allows an

attacker to control the path or content passed to handleCodeReplace().

Otherwise, exploitation may require local access or access to an internal

integration that invokes the function.

The attacker needs a way to influence the file destination and must target a

location writable by the application process. The practical impact depends on

authentication, authorization, filesystem permissions, and deployment

isolation.

Constrain every destination to a fixed trusted root after canonical

resolution, reject unsupported path forms, and use application-generated

identifiers instead of accepting arbitrary filesystem paths.

Combine secure path-handling utilities with least-privilege permissions,

focused tests for traversal and symlink edge cases, code review checks, and

monitoring for writes outside approved directories.

Find out what's already
exploitable in your codebase.