Severity:

HIGH RISK

(7.3)

Path Traversal in AgiFlow scaffold-mcp write-to-file Tool

CVE-2026-7237

Deferred

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write Outside Intended Directory

Severity:

HIGH RISK

(7.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 the write-to-file tool of AgiFlow scaffold-mcp allows attackers to manipulate the file_path argument to write files outside the intended directory.

When exposed remotely, this can enable unauthorized file creation or overwriting on the server, potentially leading to configuration tampering, data loss, or further compromise.

Affected context

This issue affects AgiFlow scaffold-mcp deployments up to version 1.0.27 that expose the write-to-file tool implemented in packages/scaffold-mcp/src/server/index.ts.

The vulnerability appears when user-controlled or externally supplied values are passed to the file_path argument without sufficient normalization or restriction to a safe base directory.

It becomes most risky in environments where the service is reachable over a network and has write permissions to sensitive parts of the filesystem.

Exploit preconditions

  • Attack surface: Remote interface or API endpoints that invoke the write-to-file tool.
  • Required access: Ability to send crafted requests or commands that control the file_path parameter.
  • Trigger point: Invocation of the write-to-file functionality with a path containing traversal sequences (for example, using parent-directory markers).
  • Why exploitation is possible: The server-side logic trusts the provided file_path and does not enforce strict directory confinement or canonicalization, allowing writes to locations outside the intended workspace.

Why this happens

The root cause aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

The write-to-file tool appears to accept a file path from the caller and use it directly when writing to disk, without robust normalization, boundary checks, or enforcement of a fixed root directory.

As a result, directory traversal sequences and absolute or crafted paths can bypass the intended storage area and target arbitrary locations that the process has permission to write to.

Potential impact

  • Creation or overwriting of files outside the designated project or workspace directory.
  • Tampering with application configuration files that reside on the same host.
  • Overwriting log files or data files, leading to denial of service or data corruption.
  • Placement of malicious files or scripts that may be executed by other components in the environment.
  • Escalation of impact if combined with other vulnerabilities or insecure system configurations.

General mitigation guidance

Mitigation centers on strictly constraining file system access and treating all file paths as untrusted input:

  • Resolve all incoming file paths against a predefined, server-side base directory and reject any path that escapes this root after canonicalization.
  • Normalize and canonicalize paths before use, and compare them against the allowed directory tree rather than relying on string checks alone.
  • Implement an allowlist of permitted directories or patterns and avoid accepting absolute paths from clients.
  • Run the service under a dedicated, least-privileged OS account with minimal write permissions and no access to sensitive system locations.
  • Consider representing file destinations by logical identifiers rather than raw paths, with the server mapping IDs to known-safe locations.

How teams detect issues like this

Detection usually involves a combination of code-centric and operational approaches:

  • Static analysis: Rules that flag direct use of user-controlled path parameters in file system operations (e.g., fs.writeFile, fs.createWriteStream) without prior normalization and directory enforcement.
  • Code review: Look for functions that accept file_path or similar parameters and verify they join paths with a fixed base directory and validate the canonical result.
  • Security testing: Dynamic tests or fuzzing that send traversal sequences in file path parameters and observe whether writes occur outside the expected directory.
  • Runtime monitoring: File integrity monitoring or audit logs that detect unexpected writes under configuration, system, or application directories.

Sources

SourceLink
github.comgithub.com/AgiFlow/aicode-toolkit/commit/c4d23592ae5fb59cfeefc4641e6826f8ac89b9c6
github.comgithub.com/AgiFlow/aicode-toolkit/issues/88
github.comgithub.com/AgiFlow/aicode-toolkit/pull/89
github.comgithub.com/AgiFlow/aicode-toolkit/releases/tag/%40agiflowai/aicode-toolkit%401.1.0
vuldb.comvuldb.com/submit/802836
vuldb.comvuldb.com/vuln/359845
vuldb.comvuldb.com/vuln/359845/cti

Frequently asked

questions

Exploitability depends on how the write-to-file tool is exposed. If it is accessible over a network or through an integration that forwards user-controlled paths, a remote attacker may be able to reach it. In more restricted deployments, the risk is limited to whoever can invoke the tool.

An attacker needs the ability to supply or influence the file_path argument to the write-to-file functionality. They do not require local shell access, but they must be able to reach the component or API that accepts file path input.

The safest pattern is to constrain all file writes to a dedicated base directory, canonicalize the requested path, and verify that the resolved path still resides under that directory. Reject or sanitize any input that attempts to escape the allowed tree or specify absolute paths.

Treat all path input as untrusted, design APIs around logical resource identifiers instead of raw paths, consistently apply path normalization and directory confinement, and include checks for path traversal in static analysis, code review guidelines, and security testing processes.

Find out what's already
exploitable in your codebase.