T09 · Insecure Skill Coding Practices
- Location
logger.py:4- Finding
Unrestricted Local File Append and Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
logger.py, lines 4-10
Vulnerability Type: Arbitrary file write through unrestricted output paths
Risk Level: MediumVulnerable Code
python def log_journal(entry, path="../logs/journal.log"): with open(path, "a") as f: f.write(f"[{datetime.now()}] {entry}\n") def log_actions(actions, path="../logs/actions.json"): with open(path, "w") as f: json.dump(actions, f, indent=2)Technical Analysis
Both public logging functions accept a caller-controlled
pathand pass it directly toopen()without path normalization, directory restriction, symlink validation, or access-policy enforcement.log_actions()is particularly sensitive because opening a file inwmode truncates an existing target before writing caller-supplied JSON.log_journal()can append caller-controlled text to any writable target. Absolute paths and traversal paths such as../../targetare not rejected.The default paths also use
../logs, causing writes outside the project directory, although this default behavior alone does not establish malicious intent. Existing internal callers use the default journal path; no built-in path-injection trigger was identified.Attack Path
- An attacker obtains influence over a call to
log_actions()orlog_journal(), including thepathargument. - The attacker supplies an absolute path, directory-traversal path, or path resolving through a symlink to a writable target outside the intended logging directory.
- Python opens the target without validating its resolved location.
log_actions()truncates and replaces the target with attacker-controlled JSON, orlog_journal()appends attacker-controlled text.- The modified file may disrupt the application or affect another process that consumes it.
Impact Assessment
Exploitation is limited to files writable by the operating-system identity run ...[truncated 523 chars]
- An attacker obtains influence over a call to
- Remediation
View remediation
Remediation Suggestions
- Remove the
pathparameter from public logging APIs unless custom destinations are required. - Configure one dedicated logging directory and resolve every destination beneath it.
- Reject absolute paths, traversal components, and any resolved path outside the approved directory.
- Reject symlink targets or open files using platform-supported no-follow protections.
- Create the logging directory explicitly with restrictive permissions.
- Apply restrictive file permissions to newly created logs.
- Avoid direct
w-mode replacement for structured data. Write to a securely created temporary file in the same approved directory, flush and synchronize it, and atomically replace the intended fixed target. - If configurable filenames are necessary, accept only a validated basename or an allowlisted identifier rather than an arbitrary path.
- Add tests covering absolute paths,
..traversal, symlinks, and targets outside the approved logging directory.
- Remove the
