[Repo Assist] fix: guard findFiles against out-of-boundary directory paths#138
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Draft
Conversation
When path.relative(workspaceRoot, fileDir) produces an absolute path (e.g. on Windows when the document and workspace root are on different drives), path.resolve(parent, directory) returns the absolute directory unchanged. The subsequent upward walk then escapes the workspace boundary, potentially scanning up to the filesystem root. This commit adds an early-exit guard: if the resolved start path is not within parent, findFiles returns null immediately. It also uses the pre-resolved parent path in the loop's stop condition for consistency. A regression test covering the out-of-boundary case is included. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
66 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 This is an automated draft PR from Repo Assist.
Problem
findFiles()inlib/utils.jscontains a subtle bug that only manifests whenpath.relative(workspaceRoot, fileDir)returns an absolute path rather than a relative one.On Windows,
path.relativebetween two paths on different drives returns an absolute path (e.g.path.relative("C:\\ws", "D:\\other")→"D:\\other"). When this is passed tofindFiles,path.resolve(parent, directory)treats it as absolute and ignoresparententirely. The loop then walks up fromD:\otherall the way toD:\— the loop'sparent === currentDirstop condition is never satisfied becauseparentis onC:\.The same issue can occur on Unix if
directoryhappens to be an absolute path for any other reason.Fix
Add an early-exit guard at the start of
findFiles: if the resolved starting directory is not withinparent(i.e. not equal toparentand not a descendant ofparent), returnnullimmediately.Also, use the pre-resolved
resolvedParentinstead of the rawparentstring in the loop's stop condition, to be consistent and correct regardless of whetherparentwas passed with a trailing separator.node --check lib/utils.js: OK ✅node --check extension.js: OK ✅No CI workflow exists in this repository; all checks are manual.
Impact