T09 · Insecure Skill Coding Practices
- Location
tools/update_canon.py:7- Finding
Import-Time Overwrite of a Hard-Coded OpenClaw Canon File
- Content
View full analysis
Vulnerability Details
File Location:
tools/update_canon.py, lines 7-8 and 90-91
Vulnerability Type: Hard-coded persistent file modification executed at module import
Risk Level: Medium
AI Agent Skill Risk Classification: T09: Insecure Skill Coding PracticesVulnerable Code
python with open('C:/Users/huang/.openclaw/workspace/story/meta/canon_bible.json', 'r', encoding='utf-8') as f: data = json.load(f)python with open('C:/Users/huang/.openclaw/workspace/story/meta/canon_bible.json', 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=2)Technical Analysis
The script reads and overwrites a developer-specific file under a persistent OpenClaw workspace. The target path is not supplied or approved by the user, is not derived from the active book, and is not validated against an authorized project root.
All processing is performed at module scope rather than inside a guarded entry point. Consequently, merely importing
tools.update_canonexecutes the complete mutation. The script inserts fixed chapter-four setup and payoff records into the selected canon file and then rewrites it directly. It does not create a backup, use a temporary file, perform atomic replacement, or validate the complete document before committing the change.Attack Path
- A user, agent, test harness, or another module imports or directly executes
tools.update_canon. - Python immediately opens the hard-coded OpenClaw canon file.
- The script inserts its fixed chapter-four records and recalculates continuity fields.
- The original file is overwritten without user confirmation or project-selection validation.
- Subsequent writing sessions consume the modified persistent state, potentially propagating incorrect canon information into later chapters.
No attacker-controlled privilege escalation is demonstrated. Exploitation is limited to the filesystem permiss ...[truncated 632 chars]
- A user, agent, test harness, or another module imports or directly executes
- Remediation
View remediation
Remediation Suggestions
- Move all executable behavior into a
main()function protected byif __name__ == "__main__":. - Require an explicit
--canon-fileor--book-dirargument rather than using a developer-specific path. - Resolve the requested path and verify that it remains under an approved books directory.
- Validate the JSON structure and required continuity fields before changing any values.
- Remove fixed chapter-specific records from the reusable utility and accept update data through validated input.
- Add a dry-run mode that displays the proposed changes.
- Require explicit confirmation before modifying an existing canon file.
- Write the new document to a temporary file in the destination directory, flush and synchronize it, and then atomically replace the destination.
- Create a timestamped backup before committing persistent changes.
- Move all executable behavior into a
