T09 · Insecure Skill Coding Practices
- Location
scripts/exwind_monitor.py:16- Finding
Predictable Shared Temporary State File Allows Symlink-Based File Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
scripts/exwind_monitor.py, lines 16 and 59–61
Vulnerability Type: Insecure temporary-file handling and symlink following
Risk Level: MediumVulnerable Code
python STATE_FILE = Path("/tmp/exwind_state.json")python def save_state(state: dict): state["seen_ids"] = state["seen_ids"][-500:] STATE_FILE.write_text(json.dumps(state, ensure_ascii=False, indent=2))Technical Analysis
The monitor stores its state at a fixed, predictable path in the globally writable
/tmpdirectory. Before writing, it does not verify the file type, ownership, permissions, or whether the path is a symbolic link.Path.write_text()follows symbolic links and truncates the resolved target.On a multi-user system, another local user may create
/tmp/exwind_state.jsonas a symbolic link to a file writable by the account running the monitor. A later scheduled execution callssave_state(), follows that link, and overwrites the target with JSON state data.The same weakness also permits direct tampering with monitor state. An attacker able to control this path can insert article IDs to suppress notifications, remove IDs to cause duplicate notifications, or provide malformed JSON to force state reinitialization.
Attack Path
- A local attacker determines the predictable state path:
/tmp/exwind_state.json. - Before the monitor writes its state, the attacker creates that path as a symbolic link to another file writable by the monitor's operating-system account.
- The scheduled monitor parses EXWIND and invokes
save_state(). Path.write_text()follows the symbolic link and truncates or replaces the target file contents with state JSON.- Depending on the selected target, this causes file corruption or modifies an Agent-owned configuration or data file.
Alternatively, the attacker creates or edits the state file directly and manipulates `seen ...[truncated 657 chars]
- A local attacker determines the predictable state path:
- Remediation
View remediation
Remediation Suggestions
- Move the state file out of the shared temporary directory and into an application-specific private state directory, such as
~/.local/state/exwind-monitor/state.json. - Create the parent directory with mode
0700and verify that it is owned by the expected user. - Reject symbolic links and unexpected file types before reading or replacing state.
- Use secure, atomic writes: create a temporary file in the same private directory with restrictive mode
0600, flush and synchronize it, and then callos.replace()to publish it atomically. - Where supported, open files using
os.open()withO_NOFOLLOW,O_CREAT, and appropriate exclusive-access flags. - Validate loaded state against the expected schema, including requiring
seen_idsto be a bounded list of valid article identifier strings. - Run the monitor as an unprivileged, dedicated account so any file-write impact remains limited.
- Move the state file out of the shared temporary directory and into an application-specific private state directory, such as
