atxtechbro / atxtechbro/dotfiles
Fix Path Escaping Issues in Filesystem MCP Server
- Dominant language
- Shell
- Stars
- 27
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
## Problem
The filesystem MCP server has issues with path escaping and special character handling that need to be fixed. Now that we have a plan to build from source (see issue #263), we need to implement specific customizations to address these problems.
## Background
Path escaping issues occur when filenames or paths contain special characters, spaces, or unusual naming patterns. The current implementation doesn't properly handle these cases, leading to failures when accessing such files.
## Specific Issues to Fix
1. **Path Escaping Problems**
- Special characters in filenames cause errors
- Spaces in paths are not properly handled
- Unicode/non-ASCII characters cause inconsistent behavior
2. **Path Traversal Handling**
- Inadequate validation of path traversal sequences (e.g., `../`)
- Potential security vulnerabilities with symbolic links
3. **Character Encoding Issues**
- Problems with non-ASCII characters in multilingual environments
## Proposed Code Changes
### 1. Improved Path Escaping
```typescript
// Current problematic implementation
function sanitizePath(path: string): string {
// Basic sanitization that doesn't handle all edge cases
return path.normalize(path);
}
// Proposed implementation
function sanitizePath(path: string): string {
// Clean the path first
const cleanPath = path.normalize(path);
// Handle special characters properly
// Additional validation for security
if (cleanPath.includes('..')) {
// Handle path traversal attempt safely
throw new Error('Path traversal not allowed');
}
return cleanPath;
}
```
### 2. Enhanced Path Validation
```typescript
function validatePath(basePath: string, requestedPath: string): string {
// Resolve to absolute paths
const absBase = path.resolve(basePath);
// Join paths safely
const fullPath = path.join(absBase, requestedPath);
const absPath = path.resolve(fullPath);
// Ensure the path is within the allowed directory
if (!absPath.startsWith(absBase)) {
throw new Error('Access denied: path outside of allowed directory');
}
return absPath;
}
```
### 3. Symbolic Link Safety
```typescript
async function resolveSymlinks(
filePath: string,
allowedDirs: string[]
): Promise {
// Resolve any symbolic links
const realPath = await fs.promises.realpath(filePath);
// Check if the resolved path is within any allowed directory
for (const dir of allowedDirs) {
const absDir = path.resolve(dir);
if (realPath.startsWith(absDir)) {
return realPath;
}
}
throw new Error('Symbolic link points outside allowed directories');
}
```
### 4. Unicode Path Support
```typescript
function handleUnicodePath(filePath: string): string {
// Use proper normalization for Unicode paths
// This ensures consistent handling across platforms
return filePath;
}
```
## Implementation Plan
1. **Fork and Clone**
- Fork the mcp-servers repository (if not already done in issue #263)
- Create a new branch for these specific fixes
2. **Implement Fixes**
- Modify the filesystem MCP server code to include the improved path handling
- Add proper error handling and logging
- Ensure backward compatibility
3. **Testing**
- Create test files with special characters, spaces, and Unicode names
- Test path traversal prevention
- Verify symbolic link handling
- Test on different operating systems
4. **Documentation**
- Document the changes made
- Update any relevant documentation
## Success Criteria
- Files with special characters can be accessed without errors
- Path traversal attempts are properly blocked
- Symbolic links are safely handled
- Unicode filenames work correctly
- No regression in existing functionality
## Tasks
- [ ] Create test files with problematic names
- [ ] Implement path escaping fixes
- [ ] Add path traversal protection
- [ ] Improve symbolic link handling
- [ ] Add Unicode support
- [ ] Test on different operating systems
- [ ] Document changes
## Related Issues
- #263 Automate Filesystem MCP Server Build from Source
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue names no source files or tests; start by locating the filesystem MCP server implementation and review issue #263 for the build context. Validate the proposed path, traversal, symlink, and Unicode requirements with platform-specific tests; done means all listed success criteria pass without regressions and the changes are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100