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_pathparameter. - 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_pathand 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_pathor 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.

