aaronsb_obsidian-mcp-plugin/github-issues/02-path-traversal-vulnerability.md
Aaron Bockelie 36301118a9 docs: Add comprehensive project documentation and security audit
- Add CONTRIBUTING.md with development guidelines
- Add SECURITY.md with vulnerability reporting policy
- Create GitHub issue templates for bugs and features
- Add PR template with checklist
- Set up GitHub Actions for testing and security scanning
- Document all security findings from code audit
- Create detailed GitHub issues for all vulnerabilities
- Update CHANGELOG with security audit results
- Add project structure documentation

This establishes proper open-source project structure and documents
all critical security issues that need to be addressed.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-12 00:14:45 -05:00

4.1 KiB

🔴 CRITICAL: Path Traversal Vulnerability in File Operations

Summary

All file operations in the ObsidianAPI class accept user-provided paths without validation, potentially allowing access to files outside the vault using path traversal sequences.

Current Behavior

  • No validation on file paths before passing to Obsidian API
  • Accepts ../, absolute paths, and special characters
  • All file operations affected: read, write, delete, move, copy

Security Impact

  • Severity: CRITICAL
  • Attack Vector: Malicious MCP client
  • Impact: Access to system files, sensitive data exposure, arbitrary file manipulation

Vulnerable Code

// obsidian-api.ts:191-195
async getFile(path: string): Promise<ObsidianFileResponse> {
  const file = this.app.vault.getAbstractFileByPath(path);  // No validation!
  if (!file || !(file instanceof TFile)) {
    throw new Error(`File not found: ${path}`);
  }
// obsidian-api.ts:212-215
async createFile(path: string, content: string): Promise<any> {
  await this.ensureDirectoryExists(path);
  const file = await this.app.vault.create(path, content);  // No validation!
  return { path: file.path };
}

Attack Scenarios

  1. Directory Traversal: ../../../etc/passwd
  2. Absolute Paths: /System/Library/Keychains/
  3. Windows Paths: C:\Windows\System32\config\SAM
  4. URL Encoded: ..%2F..%2Fsensitive.txt

Reproduction Steps

  1. Start the MCP server
  2. Send a request with malicious path:
    {
      "method": "tools/vault",
      "params": {
        "action": "read",
        "path": "../../../.ssh/id_rsa"
      }
    }
    
  3. Potentially access files outside vault

Proposed Solution

Immediate Fix: Path Validator

class PathValidator {
  private vaultRoot: string;
  
  constructor(app: App) {
    this.vaultRoot = (app.vault.adapter as any).basePath;
  }
  
  validatePath(path: string): string {
    // Reject dangerous patterns
    if (this.containsTraversal(path)) {
      throw new Error('Path traversal detected');
    }
    
    // Reject absolute paths
    if (this.isAbsolute(path)) {
      throw new Error('Absolute paths not allowed');
    }
    
    // Normalize and resolve
    const normalized = this.normalize(path);
    const resolved = path.resolve(this.vaultRoot, normalized);
    
    // Ensure within vault
    if (!resolved.startsWith(this.vaultRoot)) {
      throw new Error('Path must be within vault');
    }
    
    return normalized;
  }
  
  private containsTraversal(path: string): boolean {
    return path.includes('../') || 
           path.includes('..\\') || 
           path.includes('..%2F') ||
           path.includes('..%5C');
  }
  
  private isAbsolute(path: string): boolean {
    return path.startsWith('/') || 
           path.match(/^[A-Za-z]:/) !== null ||
           path.startsWith('\\\\');
  }
}

Long-term Solution: Comprehensive Input Validation

  1. Implement path allowlisting
  2. Add configurable security policies
  3. Integrate with Obsidian's security model
  4. Add audit logging for suspicious paths

Affected Methods

  • getFile()
  • createFile()
  • updateFile()
  • deleteFile()
  • listFiles()
  • move()
  • rename()
  • copy()
  • split()
  • combine()

Mitigation Steps

  1. Add PathValidator to all file operations
  2. Sanitize paths before any filesystem access
  3. Log all path validation failures
  4. Add configuration for allowed path patterns

Testing Requirements

  • Unit tests for path validation edge cases
  • Integration tests with malicious paths
  • Fuzzing tests for path parser
  • Performance tests for large path sets

References

Acceptance Criteria

  • PathValidator implemented and integrated
  • All file operations validate paths
  • Malicious paths are rejected with clear errors
  • Path validation is configurable
  • Audit logging implemented
  • Documentation updated

Labels

security critical path-traversal input-validation