Tainted flow: 'req' from os.environ.get (line 90, credential/environment) → urllib.request.urlopen (network output)
- Category
- Data Flow
- Confidence
- 97% confidence
- Finding
Bearer authentication to the intended Ark endpoint is legitimate, but this helper attaches ARK_API_KEY to any supplied URL without validating its destination. In particular, polling trusts the api value loaded from a state file, so an attacker-supplied or modified state file can redirect authenticated requests to an attacker endpoint and disclose the key.
- Content
python def http_json(url: str, api_key: str, method="GET", body=None, timeout=120): data = json.dumps(body, ensure_ascii=False).encode("utf-8") if body is not None else None req = urllib.request.Request(url, data=data, headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}, method=method) with urllib.request.urlopen(req, timeout=timeout) as r: return json.loads(r.read().decode("utf-8", "replace"))
