T09 · Insecure Skill Coding Practices
- Location
scripts/battery_manage.py:27- Finding
Unrestricted API Endpoint Can Disclose Authentication and Device Material
- Content
View full analysis
Vulnerability Details
File Locations:
scripts/battery_manage.py:27-28, with request sinks at57-62,90-95, and113-125scripts/get_device_token.py:45-70, with command-line endpoint configuration at96scripts/get_current_threshold.py:39-54, with command-line endpoint configuration at82
Vulnerability Type: User-controlled network destination for authenticated API requests
Risk Level: HighVulnerable Code
scripts/battery_manage.py:27-28:python JF_ENDPOINT = os.getenv("JF_ENDPOINT", "api-cn.jftechws.com") JF_BASE_URL = f"https://{JF_ENDPOINT}/gwp/v3"scripts/battery_manage.py:57-62:python url = f"{JF_BASE_URL}/rtc/device/getconfig/{device_token}" headers = get_headers(uuid, app_key, app_secret, move_card) body = { "Name": "Ability.AovAbility" } response = requests.post(url, headers=headers, json=body, timeout=30)scripts/get_device_token.py:45-70:python base_url = f"https://{endpoint}/gwp/v3" url = f"{base_url}/rtc/device/token" headers = get_headers(uuid, app_key, app_secret, move_card) body = { "sns": [device_sn], "accessToken": access_token } print(f"请求 URL: {url}") print(f"请求体:sns={[device_sn]}") response = requests.post(url, headers=headers, json=body, timeout=30) print(f"HTTP 状态码:{response.status_code}") print(f"响应原始内容:{response.text}")scripts/get_device_token.py:96:python parser.add_argument("--endpoint", default=os.getenv("JF_ENDPOINT", "api-cn.jftechws.com"), help="API 接入地址")scripts/get_current_threshold.py:39-54:python base_url = f"https://{endpoint}/gwp/v3" url = f"{base_url}/rtc/device/getconfig/{device_token}" headers = get_headers(uuid, app_key, app_secret, move_card) body = { "Name": "Dev.LowElectrMode" } response = requests.post(url, headers=headers, json=body, timeout=30) result = response.json()`scripts/g ...[truncated 2921 chars]
- Remediation
View remediation
Remediation Suggestions
-
Replace unrestricted endpoint selection with an explicit allowlist:
python ALLOWED_ENDPOINTS = { "api-cn.jftechws.com", "api-as.jftechws.com", "api-eu.jftechws.com", "api-na.jftechws.com", } endpoint = os.getenv("JF_ENDPOINT", "api-cn.jftechws.com").strip().lower() if endpoint not in ALLOWED_ENDPOINTS: raise ValueError("Unsupported JFTech API endpoint") -
Accept only bare hostnames. Reject values containing URL schemes, paths, query strings, fragments, credentials, ports, IP literals, or control characters.
-
Centralize endpoint validation in one shared function and use it in all three network-enabled scripts.
-
Do not provide unrestricted custom endpoints in production. If custom development gateways are necessary, require an explicit unsafe-development flag and display a warning before transmitting credentials.
-
Keep TLS certificate verification enabled and do not introduce a
verify=Falseworkaround. -
Prefer separate, least-privileged credentials for development and production environments.
-
Rotate device or user tokens if they may have been transmitted to an untrusted endpoint.
-
Add automated tests confirming that undocumented domains, subdomain suffix tricks, URLs, IP addresses, and malformed endpoint values are rejected.
-
