T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/chunk_writer.py:22- Finding
Unrestricted Filesystem Write and Extension Allowlist Bypass
- Content
View full analysis
str: """Resolve file_path and ensure it stays within root. Rejects symlink escapes.""" resolved = os.path.realpath(os.path.expanduser(file_path)) if root: root_resolved = os.path.realpath(os.path.expanduser(root)) if not resolved.startswith(root_resolved + os.sep) and resolved != root_resolved: raise ValueError( f"Path escapes vault boundary: '{file_path}' resolves to '{resolved}', " f"which is outside '{root_resolved}'" ) ext = os.path.splitext(resolved)[1].lower() if ext and ext not in ALLOWED_EXTENSIONS: raise ValueError(f"File extension '{ext}' not in allowlist: {ALLOWED_EXTENSIONS}") return resolved def chunk_write(file_path: str, content: str, vault_root: str | None = None) -> dict: """Write content to file in chunks, breaking at paragraph boundaries. If vault_root is provided, the resolved file_path must stay within it. """ safe_path = safe_resolve(file_path, vault_root) ``` The command-line entry point does not provide a vault root: ```python def main(): if len(sys.argv) < 3: print("Usage: chunk_writer.py ") sys.exit(1) file_path = sys.argv[1] content_source = sys.argv[2] if content_source == '-': content = sys.stdin.read() else: with open(content_source, 'r', encoding='utf-8') as f: content = f.read() result = chunk_write(file_path, content) ``` ### Technical Analysis The filesystem containment check in `safe_resolve()` is conditional on the optional `root` argument. The CLI invokes `chunk_write(file_path, content)` without suppl ...[truncated 2262 chars]- Remediation
View remediation
