mirror of
https://github.com/aaronsb/obsidian-mcp-plugin.git
synced 2026-07-22 06:45:14 +00:00
- 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>
4.1 KiB
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
- Directory Traversal:
../../../etc/passwd - Absolute Paths:
/System/Library/Keychains/ - Windows Paths:
C:\Windows\System32\config\SAM - URL Encoded:
..%2F..%2Fsensitive.txt
Reproduction Steps
- Start the MCP server
- Send a request with malicious path:
{ "method": "tools/vault", "params": { "action": "read", "path": "../../../.ssh/id_rsa" } } - 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
- Implement path allowlisting
- Add configurable security policies
- Integrate with Obsidian's security model
- Add audit logging for suspicious paths
Affected Methods
getFile()createFile()updateFile()deleteFile()listFiles()move()rename()copy()split()combine()
Mitigation Steps
- Add PathValidator to all file operations
- Sanitize paths before any filesystem access
- Log all path validation failures
- 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