T09 · Insecure Skill Coding Practices
- Location
scripts/subscan_api.py:152- Finding
Saved API Key Can Be Sent to an Arbitrary Network Destination
- Content
View full analysis
dict: """Call Subscan API and return parsed JSON response.""" headers = { "Content-Type": "application/json", "X-API-Key": api_key, "X-Refer": "subscan-api-skill", } body_bytes = json.dumps(body).encode("utf-8") # Prefer requests, fall back to urllib try: import requests # type: ignore resp = requests.post(url, data=body_bytes, headers=headers, timeout=30) resp.raise_for_status() return resp.json() except ImportError: pass ``` ```python def cmd_call(args): # Read API Key if args.key_file: api_key = check_key() if not api_key: print("ERROR: API Key not found, please run save-key first", file=sys.stderr) sys.exit(1) elif args.key: api_key = args.key else: print("ERROR: Please provide API Key via --key or --key-file", file=sys.stderr) sys.exit(1) # Parse request body try: body = json.loads(args.body) if args.body else {} except json.JSONDecodeError as e: print(f"ERROR: Invalid JSON in request body: {e}", file=sys.stderr) sys.exit(1) # Call API try: result = call_api(args.url, body, api_key) print(json.dumps(result, ensure_ascii=False, indent=2)) except Exception as e: print(f"ERROR: {e}", file=sys.stderr) sys.exit(1) ``` ```python p_call = subparsers.add_parser("call", help="Call Subscan API") p_call.add_argument("--url", required=True, help="Full API URL") p_call.add_argument("--body", default="{}", help="Request body in JSON format") p_call.add_argument("--key-file", action="sto ...[truncated 2255 chars]- Remediation
View remediation
