T09 · Insecure Skill Coding Practices
- Location
scripts/analyze_wechat.py:26- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
Vulnerability Details
File Location:
scripts/analyze_wechat.py, lines 26 and 367
Vulnerability Type: Server-Side Request Forgery (SSRF)
Risk Level: MediumVulnerable Code
python response = requests.get(url, headers=headers, timeout=30)python parser.add_argument('url', help='微信公众号文章链接')Technical Analysis
The command-line URL is passed directly to
requests.get()without validating its scheme, hostname, port, resolved IP address, or redirect destinations. Although the skill is intended to process articles hosted onmp.weixin.qq.com, the implementation does not enforce that restriction.An attacker who can control the URL can therefore cause the host running the skill to send HTTP requests to arbitrary destinations. Potential targets include loopback interfaces, private-network services, and cloud instance metadata endpoints. The
requestslibrary follows redirects by default, so an apparently permitted public URL could also redirect to an internal destination unless every redirect target is independently validated.The fetched response is parsed as article content and can be printed to the console or written into Markdown, YAML, or JSON reports. This can expose textual data returned by an internal service.
Attack Path
- The attacker supplies an arbitrary URL instead of a legitimate WeChat article URL.
argparseaccepts the value without enforcing an approved host or URL scheme.read_wechat_article()passes the attacker-controlled value directly torequests.get().- The runtime sends the request using its own network position and access.
- If the destination returns content compatible with the parser, that content is included in generated output and may be displayed or saved.
- The attacker can repeat the process with different hosts, ports, paths, or redirect chains to probe reachable internal services and retrieve textual responses.
Impact Assessment
Successful exploitation grants t ...[truncated 834 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse URLs with
urllib.parse.urlsplit()and permit only thehttpsscheme. - Require the normalized hostname to be exactly
mp.weixin.qq.com, or use a narrowly defined allowlist if additional official hosts are necessary. - Reject embedded credentials, malformed hostnames, fragments, and unexpected ports.
- Resolve the hostname before connecting and reject IPv4 and IPv6 addresses classified as loopback, private, link-local, reserved, multicast, or unspecified.
- Disable automatic redirects with
allow_redirects=False, or validate every redirect destination using the same scheme, hostname, port, and resolved-address policy before following it. - Protect against DNS rebinding by ensuring the validated address is the address used for the connection, or enforce equivalent outbound restrictions at the network layer.
- Apply an outbound firewall or proxy policy that prevents access to loopback, private networks, link-local ranges, and cloud metadata endpoints.
- Stream responses and enforce a maximum response size to limit memory exhaustion from attacker-controlled servers.
- Return a clear validation error when the supplied URL is not an approved WeChat article URL.
- Parse URLs with
