T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:72- Finding
Path Traversal Through Unvalidated Meeting Identifiers
- Content
View full analysis
\"\" " && exit 1 local file="$STORE/$id.json" [ ! -f "$file" ] && echo "Meeting $id not found" && exit 1 MM_FILE="$file" MM_TITLE="$title" MM_STORE="$STORE" python3 << 'PYEOF' import json import os; path = os.environ.get("MM_FILE","") with open(path) as f: data = json.load(f) action = { "index": len(data["actions"]) + 1, "task": "$task", "owner": "$owner", "due": "$due", "status": "open" } data["actions"].append(action) with open(path, "w") as f: json.dump(data, f, indent=2, ensure_ascii=False) print(f"✅ Action #{action['index']} added to meeting $id") print(f" Task: $task") print(f" Owner: $owner | Due: $due") PYEOF } ``` ### Technical Analysis The meeting identifier is accepted directly from a command-line argument and concatenated into a filesystem path: ```bash local file="$STORE/$id.json" ``` No numeric-format validation, canonicalization, or containment check is performed. An identifier containing traversal sequences, such as `../../some/path/record`, can resolve outside `$HOME/.bytesagain-meetings`. The existence check does not prevent traversal because it evaluates the already-traversed path. Mutating commands subsequently open and rewrite the selected file through Python. The target must be accessible to the invoking account, end in `.json` after path construction, and contain the JSON structure expected by the selected command. The same unsafe pattern affects `add-action`, `add-decision`, `view`, `exp ...[truncated 1518 chars]- Remediation
View remediation
&2 exit 1 fi ``` 2. Canonicalize both the storage directory and candidate path, then verify containment: ```bash store_real=$(realpath "$STORE") file_real=$(realpath -m -- "$STORE/$id.json") case "$file_real" in "$store_real"/*.json) ;; *) echo "Meeting path escapes the storage directory" >&2 exit 1 ;; esac ``` 3. Pass paths and user-controlled values only through environment variables or Python arguments; do not interpolate them into Python source. 4. Apply the same validation helper consistently to `add-action`, `add-decision`, `view`, `export`, and `done`. 5. Add regression tests for identifiers containing `../`, absolute paths, symbolic-link paths, empty strings, separators, and nonnumeric characters. 6. Correct the existing undefined-variable failures, but do not expose the filesystem operations until path validation is in place. ]]>
