[Repo Assist] fix: prevent findFiles from escaping parent when directory is outside workspace#94
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
… workspace If path.relative() produces a path like '../../outside' (when a PHP file is opened from outside the workspace root), findFiles was walking up from outside the parent boundary and could return a config file from an unrelated project. Add an early-exit guard: if the resolved starting directory does not sit inside resolvedParent, return null immediately. Also replace the raw string comparison 'parent === currentDir' with the normalised equivalent 'resolvedParent === currentDir' (carries forward the normalisation from the resolvedParent variable). Add a unit test that demonstrates the previous escape and confirms the fix: 'returns null when directory resolves outside parent'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 17, 2026
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, an AI assistant.
Summary
Fixes a bug in
lib/utils.jswherefindFiles()could search for config files outside the workspace root when a PHP file is opened from a path that resolves to outside the workspace.Root Cause
getStandard()computes the relative directory viapath.relative(workspaceRoot, path.dirname(filePath)). When a PHP file sits outside the workspace (e.g. opened directly from the filesystem), this produces a traversal path like"../../outside-project".findFiles(workspaceRoot, "../../outside-project", confFileNames)then callspath.resolve(workspaceRoot, "../../outside-project")which yields a path that is entirely outside the workspace. The boundary checkif (parent === currentDir) { break; }compares the rawparentstring againstcurrentDirderived from the resolved path — they can never match, so the loop walks all the way up to the filesystem root, potentially returning aphpcs.xmlfrom an unrelated project.Fix
Two changes to
lib/utils.js:resolvedDiris insideresolvedParent. If not, returnnullimmediately — no cross-project config file can be inadvertently applied.resolvedParent(result ofpath.resolve(parent)) in the loop's boundary check instead of the rawparentstring, so trailing-slash differences or redundant segments (e.g."/workspace/") never cause the guard to miss.Run with
npm run test:unit.