T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/scan.py:281- Finding
Symlink Following Allows Reads Outside the Selected Scan Root
- Content
View full analysis
List[ScanResult]: """Scan a single file for suspicious patterns""" results = [] seen_patterns: set[tuple[str, str]] = set() quoted_strings = re.compile(r'[\'"]([a-zA-Z0-9_\-]{16,})[\'"]') try: with open(file_path, 'r', encoding='utf-8', errors='ignore') as f: lines = f.readlines() ``` ```python def scan_directory(root_path: Path) -> List[ScanResult]: """Recursively scan all files in directory""" all_results = [] ignore_dirs = parse_gitignore(root_path) ignore_patterns = parse_security_config(root_path) for path in root_path.rglob('*'): if path.is_file(): # Check if filename is sensitive first sensitive = is_sensitive_filename(path.name) if sensitive: sensitive.pattern = "sensitive-filename" if sensitive.pattern not in ignore_patterns: all_results.append(sensitive) if should_scan_file(path, ignore_dirs): results = scan_file(path) ``` ### Technical Analysis The directory traversal treats every path for which `Path.is_file()` returns true as a file belonging to the scan root. File symlinks are followed by `is_file()` and later by `open()`. The implementation does not reject symlinks and does not compare the resolved candidate path against `root_path.resolve()`. Consequently, an untrusted directory can contain a symlink with a supported source extension, such as `external.py`, whose target is a readable file outside the directory selected by the user. The scanner will open and inspect that target using the privileges of the process running the scanner. This exceeds the minimum filesystem privile ...[truncated 2023 chars]- Remediation
View remediation
