T09 · Insecure Skill Coding Practices
- Location
scripts/orchestrate_and_visualize.py:17- Finding
Arbitrary File Overwrite Through Unsafe Output Handling
- Content
View full analysis
Vulnerability Details
File Location:
scripts/orchestrate_and_visualize.py, lines 17–19 and 37–39
Vulnerability Type: Predictable output paths, unsafe file overwrite, and symlink following
Risk Level: MediumVulnerable Code
python org_chart_mermaid_path = f"{output_dir}/org_chart.mmd" with open(org_chart_mermaid_path, "w") as f: f.write(org_chart_mermaid)python swimlane_mermaid_path = f"{output_dir}/swimlane.mmd" with open(swimlane_mermaid_path, "w") as f: f.write(swimlane_mermaid)Technical Analysis
The function accepts a caller-controlled
output_dirand writes to the predictable filenamesorg_chart.mmdandswimlane.mmdusing Python's truncating"w"mode. It does not verify whether either destination already exists, is a symbolic link, is a regular file, or resolves inside an approved output directory.Python follows symbolic links when
open()is used this way. Consequently, an attacker who can prepare the selected output directory can create one of the expected filenames as a symbolic link to another file. When the skill runs, the linked destination is opened, truncated, and replaced with generated Mermaid content.Attack Path
- The attacker identifies an execution in which the skill will use an output directory that the attacker can modify.
- The attacker creates
org_chart.mmdorswimlane.mmdin that directory as a symbolic link to a target file writable by the account running the skill. - A user or more privileged process invokes
orchestrate_and_visualize()with that directory. - The corresponding
open(..., "w")call follows the symbolic link and truncates the target. - Generated Mermaid content is written into the target, corrupting or replacing its prior contents.
Exploitation requires the attacker to control or prepare the output directory and the executing account to have write access to the linked target.
Impact Asses
...[truncated 600 chars]
- Remediation
View remediation
Remediation Suggestions
- Resolve the requested output directory to a canonical path and ensure it is within an explicitly approved base directory.
- Create the output directory with restrictive permissions and do not use a shared or attacker-writable directory for privileged execution.
- Reject existing symbolic links and non-regular destination files.
- Create new files atomically with exclusive and no-follow semantics, such as
os.open()withO_CREAT | O_EXCL | O_NOFOLLOW, where supported. - If overwriting is required, make it an explicit caller option and safely verify the destination before replacement.
- Prefer writing to a securely created temporary file in the same trusted directory and atomically replacing a validated regular destination.
- Apply the same validation to generated PNG destinations passed to
manus-render-diagram, because those paths are also predictable and handled by an external renderer.
