T05 · Unauthorized Access and Privilege Escalation
- Location
SKILL.md:64- Finding
Path Traversal Permits Reading Files Outside the Session Log Directory
- Content
View full analysis
list: commands = [] with open(self.log_dir / log_file, 'r') as f: for line in f: if 'command:' in line.lower() or 'user:' in line.lower(): commands.append(line.strip()) return commands ``` ### Technical Analysis The `extract_commands()` method uses the caller-controlled `log_file` value directly when constructing the path passed to `open()`. It does not reject absolute paths, parent-directory components such as `../`, symbolic links, or files outside the expected log directory. With `pathlib.Path`, joining `self.log_dir` to an absolute path causes the absolute operand to take precedence. Relative traversal components are also processed by the operating system when the file is opened. Consequently, the function is not restricted to session log files under `self.log_dir`. The returned data is filtered to lines containing `command:` or `user:`. Therefore, this is not an unrestricted full-file disclosure primitive, but it can still disclose matching lines from any file readable by the process. ### Attack Path 1. An attacker or untrusted caller gains the ability to select the `log_file` argument. 2. The caller supplies an absolute path or traversal value, such as `/path/to/sensitive-file` or `../../sensitive-file`. 3. The expression `self.log_dir / log_file` identifies a file outside the configured session log directory. 4. The process opens that file using its existing operating-system privileges. 5. Every line containing `command:` or `user:` is returned to the caller. A symbolic link placed inside the log directory could produce the same result if it points to an external file. ### Impact Assessment The vulnerability permits unauthorized inspection of files outsi ...[truncated 452 chars]- Remediation
View remediation
list: base = self.log_dir.resolve() supplied = Path(log_file) if supplied.is_absolute() or supplied.name != log_file: raise ValueError("A plain log filename is required") target = (base / supplied).resolve() if target.parent != base: raise ValueError("Log file must remain inside the log directory") if target.suffix != ".log" or not target.is_file() or target.is_symlink(): raise ValueError("Invalid log file") commands = [] with target.open("r", encoding="utf-8", errors="replace") as f: for line in f: lowered = line.lower() if "command:" in lowered or "user:" in lowered: commands.append(line.strip()) return commands ``` Apply authorization and output-redaction controls as well, because valid session logs may themselves contain sensitive information. ]]>
