T09 · Insecure Skill Coding Practices
- Location
scripts/api_test.py:31- Finding
Bearer Tokens and Sensitive Headers Can Be Sent to Arbitrary or Plaintext Destinations
- Content
View full analysis
Vulnerability Details
File Location:
scripts/api_test.py, lines 31–55 and 249–252
Vulnerability Type: Unrestricted transmission of authentication credentials
Risk Level: HighVulnerable Code
python def run_test(url, method="GET", data=None, token=None, headers=None, timeout=10): """执行单次接口测试""" req_headers = { "Content-Type": "application/json", "User-Agent": "gz-media-tester/1.0", "Accept": "application/json", } if token: req_headers["Authorization"] = f"Bearer {token}" if headers: req_headers.update(headers) body_str = "" try: start = time.time() if method.upper() == "GET": resp = requests.get(url, headers=req_headers, timeout=timeout) elif method.upper() == "POST": body_str = json.dumps(data, ensure_ascii=False) if data else "" resp = requests.post(url, headers=req_headers, data=body_str, timeout=timeout) elif method.upper() == "PUT": body_str = json.dumps(data, ensure_ascii=False) if data else "" resp = requests.put(url, headers=req_headers, data=body_str, timeout=timeout) elif method.upper() == "DELETE": resp = requests.delete(url, headers=req_headers, timeout=timeout)python parser.add_argument("url", help="接口URL") parser.add_argument("method", nargs="?", default="GET", help="HTTP方法(GET/POST/PUT/DELETE)") parser.add_argument("--data", help="POST请求体(JSON字符串)") parser.add_argument("--token", help="Bearer Token")Technical Analysis
The destination URL is entirely caller-controlled. When a token is supplied, the script unconditionally attaches it as an
Authorization: Bearerheader. Arbitrary additional headers are handled in the same way.The script does not require HTTPS, validate the destination hostname, compare the destination against an approved test envi ...[truncated 1432 chars]
- Remediation
View remediation
Remediation Suggestions
- Require
https://whenever authentication data is present and reject plaintext HTTP. - Permit credentials only for explicitly approved test and staging hostnames.
- Require interactive confirmation before forwarding credentials to a hostname not previously approved by the user.
- Reject URLs containing embedded usernames or passwords and reject schemes other than HTTP and HTTPS.
- Validate every redirect destination before allowing authentication headers to be forwarded.
- Do not accept long-lived secrets directly through command-line arguments. Prefer environment variables, protected files, standard input, or an operating-system credential store.
- Use short-lived, least-privileged test tokens and ensure production credentials are not accepted by default.
- Redact authentication values from logs, reports, exception messages, and diagnostic output.
- Require
