T09 · Insecure Skill Coding Practices
- Location
scripts/toolkit.py:44- Finding
Bearer tokens can be transmitted to an arbitrary configurable endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/toolkit.py:44-59
Vulnerability Type: Unrestricted destination for credential-bearing requests
Risk Level: HighVulnerable Code
python def env(): base = os.environ.get("HUANGLI_BASE", BASE_DEFAULT).rstrip("/") token = os.environ.get("HUANGLI_TOKEN", "") if not token: raise SystemExit(f"Error: HUANGLI_TOKEN is not set. Get token at: https://nongli.skill.4glz.com/dashboard") return base, token def http_json(url: str, token: str, method="GET", payload=None): data = None headers = {"Authorization": f"Bearer {token}"} if payload is not None: data = json.dumps(payload).encode("utf-8") headers["Content-Type"] = "application/json" req = urllib.request.Request(url, method=method, data=data, headers=headers) with urllib.request.urlopen(req) as resp: return json.loads(resp.read())The configurable base is subsequently used to construct credential-bearing requests:
python def cmd_by_date(args): base, token = env() url = f"{base}/api/lunar/date/{args.date}" print(json.dumps(http_json(url, token), ensure_ascii=False, indent=2))Technical Analysis
HUANGLI_BASEis accepted without validating its scheme, hostname, port, or origin. Every request made throughhttp_json()receives theHUANGLI_TOKENas a bearer credential.This means that a base such as
http://attacker.examplewould disclose the token over plaintext HTTP to an attacker-controlled server. An attacker-controlled HTTPS endpoint would also receive the token because the implementation does not restrict the destination to the declared service,api.nongli.skill.4glz.com.A configurable API endpoint can be legitimate for development or self-hosting, but credential-bearing production requests require explicit trust controls. Permission to query the declared almanac service does not ...[truncated 1096 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
HUANGLI_BASEoverrides from production operation unless custom servers are an explicit requirement. - Parse the endpoint with
urllib.parse.urlsplit()and require:- The
httpsscheme. - An exact allowlisted hostname.
- An approved port.
- No embedded username or password.
- No URL fragment.
- The
- Default to an exact allowlist containing only
api.nongli.skill.4glz.com. - If custom endpoints are necessary, require an explicit command-line opt-in separate from inherited environment configuration.
- Display a prominent warning and require confirmation before transmitting a token to a non-default host.
- Prevent authorization credentials from being forwarded across cross-origin redirects.
- Prefer short-lived, narrowly scoped tokens and provide prompt revocation controls.
- Remove
