fix: resolve relative paths against allowed directories instead of process.cwd()#2609
fix: resolve relative paths against allowed directories instead of process.cwd()#2609
Conversation
…ocess.cwd() Fixes issue where relative paths were incorrectly resolved against process.cwd(), causing "Access denied - path outside allowed directories" errors when the MCP server's working directory was outside the configured allowed directories. The fix implements intelligent path resolution that: 1. First tries to resolve relative paths against each allowed directory 2. Validates the resulting path is within allowed directories 3. Falls back to the first allowed directory if no valid resolution is found 4. Maintains backward compatibility by falling back to process.cwd() when no allowed directories are configured Resolves #2526 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Ola Hungerford <olaservo@users.noreply.github.com>
|
@claude do we really need to handle when there are no allowed directories set? |
|
Claude finished @olaservo's task —— View job Analysis: Need for No Allowed Directories Handling
SummaryYes, we do need to handle the case when there are no allowed directories set. Here's why: Technical AnalysisCurrent Implementation ContextLooking at the code in if (allowedDirectories.length === 0) {
// Fallback to process.cwd() if no allowed directories are set
return path.resolve(process.cwd(), relativePath);
}Why This Fallback Is Necessary
Test EvidenceThe test case at Risk AssessmentRemoving this fallback would:
RecommendationKeep the fallback handling. It's a defensive programming practice that:
The performance cost is negligible (single length check), and the reliability benefit is substantial. |
The project uses Vitest, not Jest. Replace jest.fn() with vi.fn() to fix the ReferenceError in the relative path resolution test. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
This has been open for a while and it looks like this is still an issue, so I updated it to use vitest (and also validated that the test fails without the fix). |
|
@olaservo Looks good. While you're at it, would you mind running
|
Fixes high-severity qs DoS vulnerability (GHSA-6rw7-vpxm-498p). Remaining moderate-severity issues are in dev dependencies (esbuild/vite/vitest) and require a breaking vitest v2->v4 upgrade. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@cliffhall Thanks, done! Ran |

Fixes issue where relative paths were incorrectly resolved against process.cwd(), causing "Access denied - path outside allowed directories" errors when the MCP server's working directory was outside the configured allowed directories.
The fix implements intelligent path resolution that:
Resolves #2526
Generated with Claude Code