Skip to content

fix(security): prevent path traversal via symlinks in File.read and File.list#8727

Closed
Ashwinhegde19 wants to merge 0 commit intoanomalyco:devfrom
Ashwinhegde19:dev
Closed

fix(security): prevent path traversal via symlinks in File.read and File.list#8727
Ashwinhegde19 wants to merge 0 commit intoanomalyco:devfrom
Ashwinhegde19:dev

Conversation

@Ashwinhegde19
Copy link
Copy Markdown

This PR fixes a security issue where File.read and File.list could follow symlinks outside the project directory due to lexical path checks. This allows potential path traversal. The code now resolves real paths and verifies containment before access.

Fixes:
Fixes #8313

What changed:

Updated File.read to use fs.promises.realpath() before reading.

Updated File.list to resolve paths before listing.

Added regression tests under packages/opencode/test/security/symlink.test.ts.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate/Related PRs Found:

  1. PR fix: prevent path traversal via symlinks and cross-drive paths #8316: fix: prevent path traversal via symlinks and cross-drive paths

  2. PR fix: address external_directory gaps and improve symlink checks #7515: fix: address external_directory gaps and improve symlink checks

  3. PR fix: prevent symlink escape in Filesystem.contains #6403: fix: prevent symlink escape in Filesystem.contains

Recommendation: Check PR #8316 most urgently, as it appears to be addressing the exact same vulnerability (symlink path traversal). Verify which PR was opened first and if one supersedes the other, or if they should be consolidated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Path traversal vulnerability via symlinks and cross-drive paths

1 participant