T09 · Insecure Skill Coding Practices
- Location
scripts/dispatch.py:35- Finding
Predictable Symlink-Following Audit Log Writes
- Content
View full analysis
Vulnerability Details
File Location:
scripts/dispatch.py, lines 35–37
Vulnerability Type: Symlink-following file overwrite and non-atomic audit-log creation
Risk Level: Mediumpython record_path = os.path.join(DISPATCH_DIR, "{}.json".format(task_name)) with open(record_path, "w") as f: json.dump(dispatch_record, f, indent=2)Technical Analysis
The code constructs a predictable output filename from the validated task name and opens it using Python's
"w"mode. Although task-name validation prevents path traversal,open(record_path, "w")follows symbolic links and truncates existing files. The implementation does not:- Reject symbolic links with
O_NOFOLLOW. - Use exclusive creation with
O_EXCL. - Verify the ownership and permissions of
/var/log/compute/dispatched. - Create records atomically.
- Preserve earlier records for repeated task names.
The fixed destination is under
/var/log, so the script may be run with elevated privileges. If an attacker can modify the dispatch directory, a malicious symlink named after a valid task can redirect the write to another file accessible to the script's runtime account.Attack Path
- The attacker obtains write access to
/var/log/compute/dispatched, such as through unsafe ownership or group permissions in the deployment. - The attacker creates a symbolic link such as
valid-task.jsonin that directory, pointing to a target file. - A schedule containing the valid task name
valid-taskis submitted or processed. - The script opens the predictable path in
"w"mode. - The operating system follows the symbolic link and truncates or replaces the target's contents with the dispatch JSON record.
Exploitation therefore depends on the attacker being able to modify the dispatch directory and on the runtime account having write permission to the selected target.
Impact Assessment
A successful ...[truncated 525 chars]
- Reject symbolic links with
- Remediation
View remediation
Remediation Suggestions
- Ensure
/var/log/compute/dispatchedis owned by the intended service account and is not writable by untrusted users or groups. - Open new records with
os.open()usingO_CREAT | O_EXCL | O_NOFOLLOWand a restrictive mode such as0o600, then wrap the descriptor withos.fdopen(). - Verify with
lstat()or descriptor-based checks that the destination is a regular file and not a symbolic link. - Prefer unique, append-only record names containing a securely generated identifier or high-resolution timestamp so repeated task names cannot erase earlier audit evidence.
- If records must be replaced, create a secure temporary file in the same trusted directory, flush and synchronize it, and perform an atomic replacement only after validating the destination policy.
- Run the Skill under a dedicated least-privileged account whose filesystem permissions are limited to the dispatch-log directory.
- Treat directory permission validation as a deployment requirement and fail closed if ownership or mode is unsafe.
- Ensure
