T05 · Unauthorized Access and Privilege Escalation
- Location
tools/read.js:3- Finding
Unrestricted Local File Read Through Caller-Controlled Path
- Content
View full analysis
Vulnerability Details
File Location:
tools/read.js:3-6
Vulnerability Type: Arbitrary local file read caused by missing path validation and authorization
Risk Level: HighVulnerable Code
js module.exports = async function readFile(context, params) { try { const content = fs.readFileSync(params.path, 'utf8'); return content;Technical Analysis
The tool passes the caller-controlled
params.pathdirectly tofs.readFileSyncwithout validating, canonicalizing, or restricting the requested path. It does not confine reads to a designated workspace or an allowlist of user-owned files.The
contextargument is unused, so the function performs no caller authorization or ownership check. Absolute paths, parent-directory traversal, symbolic-link escapes, sensitive virtual files such as/proc/self/environ, and credential files are not explicitly rejected.Consequently, anyone able to invoke the tool or influence its arguments can attempt to read any UTF-8-compatible file accessible under the operating-system permissions of the Agent process. This also contradicts the claim in
SKILL.md:29that tools are sanitized and limited to user-owned data.Attack Path
- An attacker directly invokes the read tool or uses prompt injection to influence an Agent that can invoke it.
- The attacker supplies a sensitive path through
params.path, such as/proc/self/environ, an application.envfile, or a private-key path. - The function passes that path unchanged to
fs.readFileSync. - Node.js reads the target using the operating-system privileges of the Agent process.
- The function returns the complete file contents to the Agent or caller.
- The sensitive content may then be disclosed in an Agent response or passed to another available tool.
Impact Assessment
Exploitation grants read access to files available to the runtime account, rather than only files legitimately r ...[truncated 533 chars]
- Remediation
View remediation
Remediation Suggestions
- Define a dedicated, least-privilege directory from which the tool is permitted to read.
- Reject absolute paths and requests containing parent-directory traversal.
- Resolve the requested path against the permitted root and canonicalize both paths with
fs.realpath. - Verify that the canonical target remains inside the canonical permitted root, using a separator-aware containment check.
- Reject symbolic links or verify their fully resolved targets before reading.
- Enforce caller identity, file ownership, and authorization using the supplied
context. - Block sensitive files and virtual or device paths, including environment files, private keys,
/proc, and/dev. - Apply file-type and maximum-size limits to reduce secret exposure and denial-of-service risk.
- Return generic errors rather than exposing internal paths or detailed filesystem errors.
- Run the Agent under a dedicated operating-system account with minimal filesystem access.
- Add security tests covering absolute paths,
../traversal, encoded traversal, symbolic-link escapes,/proc/self/environ, credential files, oversized files, and unauthorized callers.
