T09 · Insecure Skill Coding Practices
- Location
scripts/x402_client.py:12- Finding
Spending-Capable API Key Can Be Redirected to an Arbitrary or Plaintext Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/x402_client.py:12-31
Vulnerability Type: Configurable credential exfiltration destination and optional plaintext transport
Risk Level: MediumVulnerable Code
python BASE = os.environ.get("X402_BASE", "https://186.240.156.169:8791") KEY = os.environ.get("X402_API_KEY", "") ALLOW_HTTP = os.environ.get("X402_ALLOW_HTTP", "") == "1" def call(endpoint, params=None, method="GET"): if not KEY: print("ERROR: Set X402_API_KEY (get it at https://github.com/MohamedAbdisamed/x402-api)") sys.exit(1) if BASE.startswith("http://") and not ALLOW_HTTP: print("ERROR: X402_BASE uses HTTP, but the API key is spending-capable.") print(" Use HTTPS (X402_BASE=https://...), or set X402_ALLOW_HTTP=1 consciously.") sys.exit(1) url = BASE.rstrip("/") + endpoint if params: url += "?" + urllib.parse.urlencode(params) req = urllib.request.Request(url, headers={"x-api-key": KEY}) try: with urllib.request.urlopen(req, timeout=20) as r: return json.loads(r.read().decode())Technical Analysis
The client reads a spending-capable credential from
X402_API_KEYand transmits it in thex-api-keyrequest header. Sending this credential to the paid signal service is necessary for the declared premium functionality and is disclosed in both the documentation and script output.However, the credential destination is controlled by the unrestricted
X402_BASEenvironment variable. No hostname allowlist, endpoint validation, or explicit confirmation is applied before the credential is attached. An additionalX402_ALLOW_HTTP=1setting disables the default plaintext-transport protection.Consequently, process configuration can redirect the credential to an arbitrary HTTPS server or, when the bypass is enabled, transmit it over unencrypted HTTP. HTTPS to an arbitrary destina ...[truncated 2021 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the unrestricted production override or validate
X402_BASEagainst an explicit allowlist of approved HTTPS origins. - Delete the
X402_ALLOW_HTTPbypass and reject all non-HTTPS destinations when transmitting credentials. - Use a stable service hostname with a valid certificate instead of a bare IP address, and document the expected origin.
- Parse the URL before use and require an exact approved scheme, hostname, and port. Reject embedded credentials, unexpected ports, fragments, and deceptive hostname suffixes.
- Require an interactive confirmation or a separate development-only client before sending a production key to any non-default origin.
- Issue narrowly scoped keys with strict per-call, daily spending, and rate limits. Support immediate revocation and rotation.
- Avoid following cross-origin redirects while retaining the sensitive header. Explicitly ensure that
x-api-keyis never forwarded to a redirected host. - Keep the existing paid-call warning, and add documentation stating the exact recipient, data transmitted, charging behavior, key scope, and revocation procedure.
- Add automated tests confirming that HTTP URLs, unapproved hosts, malformed URLs, and cross-origin redirects cannot receive the API key.
- Remove the unrestricted production override or validate
