T09 · Insecure Skill Coding Practices
- Location
scripts/video_masking.py:25- Finding
Unvalidated API Endpoint Permits Device Token and Authentication Metadata Disclosure
- Content
View full analysis
Vulnerability Details
File Location:
scripts/video_masking.py, lines 25–66
Vulnerability Type: Unvalidated destination for sensitive network requests
Risk Level: HighVulnerable Code
python # API base address (switchable through an environment variable) JF_ENDPOINT = os.getenv("JF_ENDPOINT", "api-cn.jftechws.com") JF_BASE_URL = f"https://{JF_ENDPOINT}/gwp/v3" def get_headers(uuid: str, app_key: str, app_secret: str, move_card: int) -> Dict[str, str]: """Generate request headers containing a signature and timestamp.""" time_millis = get_time_millis() signature = generate_signature(uuid, app_key, app_secret, time_millis, move_card) return { "Content-Type": "application/json; charset=UTF-8", "uuid": uuid, "appKey": app_key, "timeMillis": time_millis, "signature": signature, "X-Request-Id": os.urandom(16).hex() } def set_video_masking(device_token: str, uuid: str, app_key: str, app_secret: str, move_card: int, enable: bool) -> Dict[str, Any]: """ Set the video privacy-mask state. API: POST /gwp/v3/rtc/device/setconfig/{deviceToken} Name: OPPTZControl """ url = f"{JF_BASE_URL}/rtc/device/setconfig/{device_token}" headers = get_headers(uuid, app_key, app_secret, move_card) body = { "Name": "OPPTZControl", "General.OneKeyMaskVideo": [ { "Enable": enable } ] } response = requests.post(url, headers=headers, json=body, timeout=30) result = response.json()Technical Analysis
The
JF_ENDPOINTenvironment variable is inserted directly into the request URL without hostname validation or an allowlist. The documentation identifies only four legitimate regional API hosts, but the implementation permits requests to an ...[truncated 2038 chars]- Remediation
View remediation
Remediation Suggestions
- Replace the unrestricted endpoint setting with a region selector mapped internally to an immutable allowlist:
api-cn.jftechws.comapi-as.jftechws.comapi-eu.jftechws.comapi-na.jftechws.com
- If endpoint customization must remain available, parse it as a hostname and reject:
- Unknown domains
- URL schemes
- User-information components
- Ports
- Paths and query strings
- IP address literals
- Encoded or ambiguous hostnames
- Disable HTTP redirects for authenticated requests, or validate every redirect destination against the same allowlist.
- Avoid placing bearer-like device tokens in URL paths where the upstream API permits an authorization header instead.
- Ensure tokens are narrowly scoped, short-lived, revocable, and restricted to the minimum required device operation.
- Add automated tests confirming that unsupported hosts and redirect destinations are rejected before any credentials are transmitted.
- Replace the unrestricted endpoint setting with a region selector mapped internally to an immutable allowlist:
