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
Good bug fix. path.resolve(projectPath, directoryPath) alone doesn't stop ../project-evil (shares prefix but escapes) or symlinks that resolve outside the project root, and this PR closes both holes by resolving both sides through fs.realpath and checking containment with the existing isPathInside helper before calling readdir. That matches the project's stated bug (#463).
The test suite in sdk/src/__tests__/list-directory.test.ts is thorough: it exercises project-root listing, valid child dirs, .. traversal, sibling-prefix traversal, and both an escaping and a non-escaping symlink. That's exactly the kind of edge-case coverage a security fix needs.
A couple of things worth double-checking before porting:
fs.realpath(resolvedPath) will throw if the directory doesn't exist (ENOENT) rather than surfacing a clean "invalid path" error — worth confirming the existing catch block in list-directory.ts produces a sane error message for that case, since previously a missing directory would fail inside readdir with the same behavior, but now it fails one line earlier at realpath.
Adding realpath to CodebuffFileSystem (common/src/types/filesystem.ts) means every other implementer/mocker of that interface across the codebase needs to supply it — you've updated the shared mock in common/src/testing/mocks/filesystem.ts, but it's worth greping for other places that construct a CodebuffFileSystem-shaped object by hand (not through the mock) to make sure nothing breaks at the type level.
Modest, well-scoped diff with tests — this is the kind of PR that's easy to review and port by hand.
Added a regression test for a missing requested directory. It pins the existing behavior after the new realpath step: the tool returns the normal Failed to list directory: ENOENT... JSON error and never calls readdir.
I also checked the CodebuffFileSystem usages/hand-built mocks. The shared mock is updated with realpath, and this PR's existing common + sdk typechecks already exercise the interface change. No additional concrete implementation was found that needs a production change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
realpath.Fixes #463
Validation
bun run --cwd common typecheckbun run --cwd sdk typecheckbun run --cwd sdk test— 518 passed, 0 failedbun test common/src/__tests__/project-file-tree.test.ts— 12 passed, 0 failedgit diff --check