opencode
opencode copied to clipboard
fix: prevent symlink escape in Filesystem.contains
The Filesystem.contains() function previously performed only lexical path checking, which could be bypassed using symlinks inside the project directory. An attacker could create a symlink pointing to sensitive files outside the project (e.g., ~/.ssh/id_rsa), and the file tools would allow reading them.
This fix:
- Uses
realpathSyncto resolve symlinks before checking containment - Falls back to lexical check if realpath fails (e.g., file doesn't exist)
- Adds explicit handling for Windows cross-drive paths (D:\ vs C:)
- Removes the TODO comments that documented this issue