You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Potential path traversal in file read/write tools #11703
The file read and write tools use path.resolve/path.join with user input, which could potentially allow path traversal attacks in certain scenarios, particularly when symlinks are involved.
While assertExternalDirectory provides protection, the check uses Filesystem.contains() which relies on string-based path comparison via path.relative(). This approach has known weaknesses:
Symlink bypass: If a directory within the project contains a symlink pointing outside, path.resolve will follow it but Filesystem.contains() won't detect it
Race condition (TOCTOU): The path is validated but could change between validation and use
Impact
Severity: Medium (mitigated by existing checks)
Type: Path Traversal
Conditions: Requires symlinks or specific timing
Suggested Fix
Use fs.realpath() to resolve symlinks before checking containment:
letfilepath=params.filePathif(!path.isAbsolute(filepath)){filepath=path.resolve(Instance.directory,filepath)}// Resolve symlinks to get actual pathconstrealFilepath=awaitfs.realpath(filepath).catch(()=>filepath)awaitassertExternalDirectory(ctx,realFilepath,{...})
Consider using fs.openSync with O_NOFOLLOW flag for symlink-sensitive operations
Activity
github-actions commentedon Apr 3, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.