T09 · Insecure Skill Coding Practices
- Location
scripts/extract_cookies.py:121- Finding
Authentication Cookies Are Extracted, Printed, and Cached in Plaintext
- Content
View full analysis
str: os.makedirs(CACHE_DIR, exist_ok=True) domain_hash = hashlib.md5(domain.encode()).hexdigest()[:8] safe_domain = domain.replace(".", "_").replace(":", "_") return os.path.join(CACHE_DIR, f"{safe_domain}_{domain_hash}.txt") ``` ```python ws.send(json.dumps({ "id": 1, "method": "Network.getCookies", "params": {"urls": [target_url]} })) result = json.loads(ws.recv()) ws.close() cookies = result.get("result", {}).get("cookies", []) if not cookies: print(f"WARNING: No cookies found for {target_url}", file=sys.stderr) return "" cookie_str = "; ".join([f"{c['name']}={c['value']}" for c in cookies]) return cookie_str ``` ```python if cookie_str: with open(cache_path, "w") as f: f.write(cookie_str) print(f"# Saved to: {cache_path}", file=sys.stderr) print(cookie_str) else: print("ERROR: Failed to extract cookies", file=sys.stderr) sys.exit(1) ``` ### Technical Analysis The script uses Chrome DevTools Protocol `Network.getCookies` to retrieve browser cookies for the target URL. This interface may return sensitive session cookies, including HttpOnly cookies that normal page JavaScript cannot access. The resulting cookie string is: 1. Written unencrypted to a predictable directory under `/tmp`. 2. Created without explicitly enforcing owner-only permissions such as mode `0600`. 3. Retained for up to one hour. 4. Printed directly to standard output, where it may be captured by shell history-adjacent tooling, agent transcripts, CI logs, parent processes, or generated command output. The ...[truncated 1764 chars]- Remediation
View remediation
