T09 · Insecure Skill Coding Practices
- Location
scripts/fetch_data.py:35- Finding
Authentication Token Can Be Sent to an Arbitrary Configurable Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/fetch_data.py:35-38,scripts/fetch_data.py:88-98, andscripts/fetch_data.py:178-185
Vulnerability Type: Unrestricted authentication endpoint configuration
Risk Level: HighVulnerable Code
python def get_base_url(): """Get the base URL.""" config = get_config() return config.get("base_url", DEFAULT_BASE_URL).rstrip("/")python token = get_token() base_url = get_base_url() params = {"query": query, "skillCode": SKILL_CODE} if start_date: params["startDate"] = start_date if end_date: params["endDate"] = end_date query_string = urllib.parse.urlencode(params) url = f"{base_url}/research_pilot_service/openapi/skills/open/search/announcement?{query_string}" request = urllib.request.Request(url) request.add_header("Authorization", token) request.add_header("Content-Type", "application/json")python if sys.argv[1] == "--set-url": if len(sys.argv) < 3: print("Error: provide a URL value", file=sys.stderr) print("Usage: python fetch_data.py --set-url <url>", file=sys.stderr) sys.exit(1) set_config("base_url", sys.argv[2]) sys.exit(0)Technical Analysis
The script permits
base_urlto be replaced with an arbitrary value through the undocumented--set-urlcommand. No scheme validation, HTTPS requirement, hostname allowlist, or origin check is applied. The same code then unconditionally attaches the configured authentication token to theAuthorizationheader.Consequently, changing the endpoint causes subsequent queries to disclose the token to the configured server. Allowing an
http://endpoint also exposes the token, query, and response to plaintext network interception. Depending on network access, arbitrary endpoint support may additionally allow requests to internal services, although the fixed API path limits the reachable req ...[truncated 1613 chars]- Remediation
View remediation
Remediation Suggestions
- Remove the
--set-urlfeature if alternate endpoints are not essential to the declared functionality. - If endpoint customization is required, parse the URL with
urllib.parse.urlparseand enforce:- The
httpsscheme. - An explicit allowlist of trusted hostnames.
- An expected port.
- Rejection of embedded credentials, fragments, IP literals, loopback addresses, and private or link-local destinations where they are not required.
- The
- Only attach the
Authorizationheader after verifying that the final request origin is trusted. - Prevent redirects from forwarding credentials to a different origin, or disable redirects and validate each redirect destination.
- Store endpoint configuration separately from credentials and warn or fail closed if the endpoint is invalid.
- Document every supported endpoint override and its security implications.
- Add tests confirming that HTTP, unapproved domains, localhost, private addresses, and cross-origin redirects are rejected.
- Remove the
