T09 · Insecure Skill Coding Practices
- Location
scripts/xhs_client.py:42- Finding
Remote Endpoint Override Can Expose Sensitive Request Data
- Content
View full analysis
Vulnerability Details
File Location:
scripts/xhs_client.py:42-56,scripts/xhs_client.py:91-100, andscripts/xhs_client.py:153-159
Vulnerability Type: Arbitrary remote endpoint override and potential plaintext transmission of sensitive data
Risk Level: MediumVulnerable Code
python def _resolve_base_url(): url = os.environ.get("XHS_MCP_BASE_URL", _DEFAULT_BASE_URL).rstrip("/") try: host = urlparse(url).hostname or "" except ValueError: print(f"❌ Invalid XHS_MCP_BASE_URL: {url!r}", file=sys.stderr) sys.exit(1) if host not in _LOOPBACK_HOSTS and os.environ.get("XHS_ALLOW_REMOTE") != "yes": print( f"❌ Refusing non-loopback endpoint: {url}. Set XHS_ALLOW_REMOTE=yes " "to override at your own risk.", file=sys.stderr, ) sys.exit(1) return urlpython def _request(method, path, **kwargs): """Unified request handler with consistent error handling. Returns parsed JSON on success, or an error dict on failure. Never exits the process — callers decide how to handle errors. """ kwargs.setdefault("timeout", DEFAULT_TIMEOUT) url = f"{BASE_URL}{path}" try: resp = requests.request(method, url, **kwargs)python payload = { "feed_id": feed_id, "xsec_token": xsec_token, "load_all_comments": load_comments } data = _request("POST", "/api/v1/feeds/detail", json=payload)Technical Analysis
The client defaults to a loopback MCP endpoint, but the
XHS_ALLOW_REMOTE=yesenvironment variable completely bypasses the loopback restriction.XHS_MCP_BASE_URLmay then identify an arbitrary remote server, including an unencryptedhttp://endpoint.Requests sent through this configurable endpoint can contain:
- Xiaohongshu
xsec_tokenvalues and feed identifiers. - Search terms and filtering prefere ...[truncated 1907 chars]
- Xiaohongshu
- Remediation
View remediation
Remediation Suggestions
- Remove
XHS_ALLOW_REMOTEand enforce a loopback-only endpoint if remote operation is not part of the declared functionality. - Resolve the configured hostname and verify that every resulting address is loopback, rather than relying only on the literal hostname.
- Restrict accepted schemes to
httpfor verified loopback endpoints, or requirehttpsfor any explicitly supported remote connection. - If remote operation is genuinely required:
- Document it as a separate high-risk mode.
- Use a strict endpoint allowlist.
- Require HTTPS with certificate validation.
- Prefer mutual TLS or another authenticated channel.
- Require a dedicated command-line confirmation rather than a reusable environment-variable bypass.
- Disable redirects or validate every redirect destination to prevent a trusted endpoint from redirecting sensitive requests off-host.
- Update
SKILL.mdso its security guarantees accurately reflect runtime behavior. - Avoid logging or reflecting complete remote response bodies where they may contain sensitive information.
- Remove
