T09 · Insecure Skill Coding Practices
- Location
SKILL.md:107- Finding
Import-Time Example Code Mutates Persistent Task Data
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 107-119
Vulnerability Type: Import-time side effects and unauthorized local data modification
Risk Level: MediumVulnerable Code
python todo = QuickTodo() todo.add("学习Transformer架构", priority="high") todo.add("写周报", priority="medium", due="2026-05-30") todo.add("整理书签", priority="low") # 查看待办 for t in todo.list(filter_done=False): pri = {"high": "🔴", "medium": "🟡", "low": "⚪"}[t["priority"]] print(f"[{t['id']}] {pri} {t['task']}") # 标记完成 todo.done(1)Technical Analysis
The example creates a
QuickTodoinstance and performs persistent write operations at module scope. Noif __name__ == "__main__":guard separates demonstration behavior from the importable class implementation.The documented command-line examples import the class with statements such as:
bash python -c "from quick_todo import QuickTodo; QuickTodo().done(1)"If the supplied implementation is copied into
quick_todo.py, Python executes all module-scope statements during the import. Consequently, every import appends three demonstration tasks toquick_tasks.jsonand marks task ID 1 as completed before the caller's requested operation runs.This is an insecure coding practice because a read-like module loading operation unexpectedly changes persistent user data. The behavior is deterministic rather than attacker-controlled, but it violates data-integrity expectations and can repeatedly corrupt the task list.
Attack Path
- A user copies the documented Python implementation into
quick_todo.py. - The user invokes one of the documented commands that imports
QuickTodo. - Python evaluates the module-level example code during import.
- Three sample tasks are appended to
quick_tasks.json. - Task ID 1 is marked complete.
- Only after those side effects does Python execute the operation explicitly requested by the us ...[truncated 630 chars]
- A user copies the documented Python implementation into
- Remediation
View remediation
Remediation Suggestions
Place all executable demonstration code behind a main-module guard:
python if __name__ == "__main__": todo = QuickTodo() # Demonstration operations belong here.Prefer moving examples entirely into documentation or a separate example script so that the importable module contains only class and function definitions.
Add an automated test that imports
quick_todoin a temporary directory and verifies that importing it neither creates nor modifiesquick_tasks.json. The command-line interface should also use an explicit entry point whose selected action is the only operation performed.
