T09 · Insecure Skill Coding Practices
- Location
scripts/receive.py:57- Finding
Path Traversal Enables Arbitrary JSON File Creation and Overwrite
- Content
View full analysis
Dict[str, Any]: bids_dir = STATE_DIR / "bids" / req_id if not bids_dir.exists(): return {"error": f"Request {req_id} has no bid directory"} bids = [] for bid_file in bids_dir.glob("*.json"): bid = json.loads(bid_file.read_text()) bids.append(bid) result_file = STATE_DIR / "requirements" / f"{req_id}_result.json" result_file.parent.mkdir(parents=True, exist_ok=True) result_file.write_text(json.dumps(result, indent=2, ensure_ascii=False)) ``` Notification paths are constructed similarly: ```python notif_file = NOTIFICATIONS_DIR / f"{req_id}_{notification_type}.json" notif_file.write_text(json.dumps(notification, indent=2, ensure_ascii=False)) ``` ### Technical Analysis The values of `req_id` and `bid_id` originate in externally supplied bid JSON. They are used directly as filesystem path components without a strict identifier format, rejection of path separators, canonicalization, or verification that the resolved destination remains inside the intended state directory. `pathlib.Path` does not automatically prevent traversal. Values containing `../` can escape the intended directory. An absolute path used as a later path component can also replace the preceding bas ...[truncated 1587 chars]- Remediation
View remediation
