The vulnerability is a Server-Side Request Forgery (SSRF) caused by a Time-of-check Time-of-use (TOCTOU) weakness, specifically a DNS rebinding attack. The application checks if a user-provided URL points to a private IP address before making a request. This check is performed by the validate_request_url function, which in turn calls is_private_url. The is_private_url function resolves the hostname to an IP address to perform the check. However, a malicious actor could have their DNS server return a safe, public IP during this initial check, and then return a private, internal IP (like 127.0.0.1) when the application makes the actual HTTP request. This bypasses the security check and allows the attacker to make the server issue requests to internal services.
The patch addresses this by monkey-patching Python's socket.getaddrinfo function. The new implementation (safe_getaddrinfo) caches the IP addresses returned from the first DNS lookup for a given host within the request context. On subsequent lookups for the same host, it checks if any new, private IP addresses have appeared. If so, it raises an InsecureRequestError, preventing the DNS rebinding attack. The functions validate_request_url and is_private_url are the core components of the vulnerable validation logic that was bypassed.