T09 · Insecure Skill Coding Practices
- Location
scan_uis.py:65- Finding
Loopback Probe Can Escape to Arbitrary Hosts Through HTTP Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scan_uis.py:65-68
Vulnerability Type: Server-Side Request Forgery through unrestricted redirect following
Risk Level: MediumVulnerable Code
python url = f"http://127.0.0.1:{port}/" req = urllib.request.Request(url, headers={"User-Agent": "local-uis-scan"}) try: with urllib.request.urlopen(req, timeout=1.4) as r: status = r.statusTechnical Analysis
The initial URL is restricted to
127.0.0.1, buturllib.request.urlopenfollows HTTP redirects by default. It also uses the standard environment-aware proxy configuration. The code does not validate redirect destinations or ensure that each resulting connection remains on a loopback address.Consequently, a locally listening HTTP service can return a redirect to an arbitrary external or internal host. This contradicts the assertion in
SKILL.md:31that the tool does not probe other hosts. The limitation is acknowledged separately inREADME.md:53-54, but no technical control enforces the intended boundary.The request uses a fixed HTTP
GEToperation and does not explicitly attach credentials. Nevertheless, redirect-driven requests can reach services available from the victim machine, including private network resources that are inaccessible to the attacker directly.Attack Path
- An attacker starts or compromises an HTTP service listening on a local port.
lsofidentifies the port, and the scanner sends a request tohttp://127.0.0.1:<port>/.- The malicious service responds with a
30xstatus and an attacker-selectedLocationheader. urllib.request.urlopenfollows the redirect without validating the destination.- The scanner connects to the selected external host, private-network service, or other non-loopback destination using the victim machine's network access.
- The destination receives the request, and a state-changing endpoint could potentially ...[truncated 802 chars]
- Remediation
View remediation
Remediation Suggestions
- Construct a custom
urllibopener that disables automatic redirects. - Disable environment-derived proxy handling by installing an empty
ProxyHandler. - If redirects are required, validate every redirect destination before following it:
- Require the
httpscheme. - Resolve the hostname.
- Require every resolved address to be loopback.
- Reject credentials, malformed authorities, and non-loopback IPv4 or IPv6 addresses.
- Require the
- Apply the destination validation again after DNS resolution and immediately before connection to reduce resolution-based bypasses.
- Add tests covering redirects to public addresses, private network addresses, IPv6 addresses, and proxy-configured environments.
- Update
SKILL.mdso its safety claims accurately match the implemented guarantees.
A hardened implementation should use a no-redirect, no-proxy opener unless redirect support is essential.
- Construct a custom
