T09 · Insecure Skill Coding Practices
- Location
scripts/check_404.py:54- Finding
Insufficient URL Validation Enables Blind Server-Side Request Forgery
- Content
View full analysis
Vulnerability Details
File Location:
scripts/check_404.py:54-56,scripts/check_404.py:72-74,scripts/check_404.py:108-110, andscripts/check_sites.py:25-27
Vulnerability Type: Blind server-side request forgery through weak hostname validation and unrestricted redirects
Risk Level: MediumVulnerable Code
python # scripts/check_404.py:54-56 full_url = urljoin(base_url, href) # 只保留同域名的商品页 if base_url.split("//")[1].split("/")[0] in full_url: links.add(full_url)python # scripts/check_404.py:72-74 response = requests.get(url, timeout=timeout, allow_redirects=True, headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36" })python # scripts/check_404.py:108-110 resp = requests.get(category_url, timeout=timeout, headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36" })python # scripts/check_sites.py:25-27 response = requests.get(url, timeout=timeout, allow_redirects=True, headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36" })Technical Analysis
Product links are accepted by testing whether the configured shop hostname appears anywhere in the complete URL as a substring. This does not establish that the parsed destination hostname is the configured hostname.
For example, an attacker-controlled URL can contain the legitimate hostname in its path or query string while its actual hostname points elsewhere. Such a URL can pass the substring condition and subsequently be requested by
check_product_page.Requests also follow redirects automatically. Neither the initial destination nor each redirect target is checked for loopback, link-local, private, reserved, or cloud metadata addresses. A legitimate shop page that has been compromised, or an endpoint that returns an attacker-controlled redirect, can therefore ...[truncated 1881 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse every URL with
urllib.parse.urlsplitand compare normalized hostnames for exact equality or against a narrowly defined allowlist. - Permit only the
httpandhttpsschemes. - Reject URLs containing user information, malformed ports, or ambiguous hostname encodings.
- Disable automatic redirects and process redirects manually.
- Validate every redirect destination before following it.
- Resolve destination hostnames and reject loopback, private, link-local, multicast, unspecified, and reserved IPv4 and IPv6 ranges.
- Repeat IP validation after every DNS resolution to mitigate DNS rebinding.
- Explicitly block known cloud metadata addresses.
- Apply the same validation to configured base URLs, category URLs, product links, and site-check URLs.
- Where possible, maintain an explicit list of approved shop hostnames and ports rather than accepting arbitrary configuration values.
- Parse every URL with
