T09 · Insecure Skill Coding Practices
- Location
weixin_reader.py:31- Finding
Arbitrary URL Fetching and Redirect-Based Server-Side Request Forgery
- Content
View full analysis
Vulnerability Details
File Location:
weixin_reader.py, lines 31-32
Vulnerability Type: Server-Side Request Forgery (SSRF) caused by unrestricted URL fetching
Risk Level: MediumVulnerable Code
python with httpx.Client(follow_redirects=True, timeout=30) as client: resp = client.get(url, headers=headers)Technical Analysis
The URL supplied by the caller is passed directly to
httpx.Client.get()without validating its scheme, hostname, port, or resolved IP address. AlthoughSKILL.mdstates that the skill is intended formp.weixin.qq.comarticle URLs, the implementation does not enforce that restriction.The HTTP client is also configured with
follow_redirects=True. Therefore, validating only the initial URL outside this code would be insufficient unless every redirect destination were also checked. An external server could redirect the request to a loopback, private, link-local, or otherwise restricted address.Requests are made with the network access of the process running the skill. The response is subsequently parsed as HTML. If an internal response contains elements matching the expected WeChat selectors, its content may be printed. Even when extraction fails, response timing and application behavior may permit internal-service probing.
Attack Path
- An attacker or untrusted user provides an arbitrary URL as the skill's command-line argument.
- The URL is passed to
read_wechat_article()without enforcing the documented WeChat hostname restriction. httpxsends a request to the supplied destination.- The attacker may use a direct internal URL, such as a loopback or private-network address, or provide an external URL that redirects to an internal destination.
- Because redirects are followed automatically without destination validation, the process accesses the resulting target using the Agent host's network position.
- Internal response characteristics may ...[truncated 927 chars]
- Remediation
View remediation
Remediation Suggestions
- Enforce an explicit hostname allowlist containing only
mp.weixin.qq.comand any additional WeChat domains that are strictly required and documented. - Permit only HTTPS URLs and reject URLs containing credentials, nonstandard ports, ambiguous host representations, or unsupported schemes.
- Normalize the hostname and perform an exact hostname or properly bounded subdomain comparison; do not use substring matching.
- Resolve the hostname before connecting and reject all loopback, private, link-local, multicast, reserved, and unspecified IPv4 and IPv6 addresses.
- Disable automatic redirects and process redirects manually. Apply the same scheme, hostname, port, and resolved-IP checks to every redirect target.
- Protect against DNS rebinding by ensuring the validated address is the address actually used for the connection, or enforce equivalent restrictions through a controlled outbound proxy.
- Set limits for response size and redirect count to reduce resource-exhaustion risks.
- Call
resp.raise_for_status()and return sanitized error messages rather than exposing raw network exception details. - Apply outbound firewall or proxy controls so the skill cannot access metadata endpoints, loopback services, or private networks even if application validation is bypassed.
- Enforce an explicit hostname allowlist containing only
