Repository navigation
feat(loader): add path traversal protection - #20
Conversation
Add security feature to prevent malicious ledger files from accessing files outside the ledger directory via include directives. - Add `with_path_security(bool)` to enable/disable protection - Add `with_root_dir(PathBuf)` to set custom root directory - Add `PathTraversal` error variant for security violations - Includes are validated to stay within the root directory This protects against attacks where a crafted .beancount file uses relative paths like `include "../../../etc/passwd"` to escape the intended directory. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
|
||
| // Set root directory for path security if enabled but not explicitly set | ||
| if self.enforce_path_security && self.root_dir.is_none() { | ||
| self.root_dir = canonical.parent().map(Path::to_path_buf); |
There was a problem hiding this comment.
🤖 Security Issue: Path traversal protection can be bypassed when the main beancount file is located at the filesystem root. When canonical.parent() returns None for root files (e.g., /ledger.beancount), root_dir remains None, causing the security check at line 295 to be skipped entirely
Severity: HIGH
Category: path_traversal
Tool: ClaudeCode AI Security Analysis
Exploit Scenario: An attacker who can control where a beancount file is loaded from could place it at the filesystem root (e.g., /malicious.beancount). When this file contains 'include "/etc/passwd"' and path security is enabled, the protection fails because root_dir is None, allowing arbitrary file reads. This could occur in web services that process user-uploaded beancount files or in CI/CD pipelines that process untrusted ledger files
Recommendation: When canonical.parent() returns None, either: (1) Set root_dir to Path::new("/") to restrict includes to the root directory only, or (2) Fail with an error indicating that files at the filesystem root cannot use includes when security is enabled
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
feat(loader): add path traversal protection
feat(loader): add path traversal protection
Summary
with_path_security(bool)method to enable/disable protectionwith_root_dir(PathBuf)method to set custom root directoryPathTraversalerror variant for security violationsMotivation
This protects against attacks where a crafted .beancount file uses relative paths like
include "../../../etc/passwd"to escape the intended directory.Test plan
🤖 Generated with Claude Code