[Routine - QP] fix: close prefix-match bypass in PathUtils.validatePath#44
Draft
winterdrive wants to merge 1 commit into
Draft
[Routine - QP] fix: close prefix-match bypass in PathUtils.validatePath#44winterdrive wants to merge 1 commit into
winterdrive wants to merge 1 commit into
Conversation
startsWith() treated any path whose string prefix matched the workspace root as inside the workspace, so a sibling directory like "/foo/bar-evil" would pass validation against workspace root "/foo/bar". Require an exact match or a path.sep-bounded prefix instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Jul 2, 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.
1. Pre-flight Check
Open PRs / active branches checked before starting (
gh pr list --state open,git branch -r):fix/quick-create-workspace-ux(open, draft) — touchessrc/commands.ts,src/promptProvider.ts,src/test/unit/promptProviderMultiroot.test.ts. No overlap with this PR.routine/qp-fix-*branches exist on the remote ([Routine - QP] refactor: replace deprecated String.substr() with substring() #33–[Routine - QP] fix: guard VersionHistoryService against corrupted/malformed history JSON #41) but all are CLOSED, not merged — they are stale duplicate attempts at guardingClipboardManager.ts/PromptManager.ts/VersionManager.ts/VersionHistoryService.ts/aiEngine.ts/openAIClient.tsagainst corrupted JSON. I confirmedVersionHistoryService.loadHistory()on currentmasteralready has theisValidHistoryshape-guard andSyntaxErrorhandling those closed PRs proposed (verified via the passingversionHistoryService.test.tssuite), so that area is already covered and I avoided touching it again to prevent further duplicate churn.src/core/PathUtils.tsand its test filesrc/test/unit/pathUtils.test.ts, neither of which appears in any open PR's diff or in the closed routine branches' file lists. No overlap.2. Changes
PathUtils.validatePath()usednormalizedPath.startsWith(normalizedRoot)to check whether a resolved path lies inside the workspace root. This is a plain string-prefix check, so a sibling directory that merely shares a name prefix (e.g. workspace root/foo/barvs. a path resolving to/foo/bar-evil/file.json) would incorrectly pass validation.path.sep(normalizedPath === normalizedRoot || normalizedPath.startsWith(normalizedRoot + path.sep)).pathUtils.test.ts: one confirming the sibling-directory prefix bypass is now rejected, and one confirming the workspace root itself is still accepted.mcp-server/src/tools/, does not add/remove/update dependencies, and does not touchpackage.json/package-lock.json/CHANGELOG.md.3. Safety Verification
Commands run locally, all passed:
npx tsc -p ./— no errorsnpm run test(Jest,--runInBand) — 7 suites / 109 tests passed, including the 2 new testsNo
lintorformat:checkscript exists inpackage.json, so those steps were skipped.4. CI / Release Gate Note
This is a daily routine Draft PR. Package version bump and CHANGELOG consolidation are intentionally deferred to the weekend release/integration PR. If CI's version-bump gate blocks this PR for lacking a version bump or the
release-readylabel, that is expected release-readiness behavior, not a code validation failure.