fix(security): prevent path traversal via symlinks #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical security vulnerability that allowed directory traversal via symbolic links. The
File.readandFile.listtools previously relied on lexical path validation (path.relative), which could be bypassed by creating a symlink inside the project pointing to an external file or directory.What was broken
File.readallowed reading files outside the project if accessed via a symlink.File.listallowed listing directories outside the project if accessed via a symlink.Instance.containsPath(lexical check) returned true for these symlinks because it did not resolve them.Fix approach
packages/opencode/src/file/index.ts:File.readto resolve the path usingfs.promises.realpathafter confirming existence but before reading content.File.listto resolve the path usingfs.promises.realpathbefore listing content.Instance.containsPath.Verification
packages/opencode/test/security/symlink.test.tsthat:File.read.Checklist
File.readandFile.listPR created automatically by Jules for task 9454945919874623948 started by @Ashwinhegde19