s0md3v / velocity

DNS caching for humans
GNU General Public License v3.0
89 stars 23 forks source link

Caching of getaddrinfo pins port #2

Open jayvdb opened 4 years ago

jayvdb commented 4 years ago
>>> socket.getaddrinfo('www.ros.org', 80)
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('140.211.9.4', 80)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('140.211.9.4', 80)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_RAW: 3>, 0, '', ('140.211.9.4', 80)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('2605:bc80:3010:104::8cd3:904', 80, 0, 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('2605:bc80:3010:104::8cd3:904', 80, 0, 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_RAW: 3>, 0, '', ('2605:bc80:3010:104::8cd3:904', 80, 0, 0))]
>>> socket.getaddrinfo('www.ros.org', 443)
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('140.211.9.4', 443)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('140.211.9.4', 443)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_RAW: 3>, 0, '', ('140.211.9.4', 443)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('2605:bc80:3010:104::8cd3:904', 443, 0, 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('2605:bc80:3010:104::8cd3:904', 443, 0, 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_RAW: 3>, 0, '', ('2605:bc80:3010:104::8cd3:904', 443, 0, 0))]

velocity patched_addr would cache the first result, pinning port 80 into the cache, and then a request for port 443 will return results for port 80.

This breaks usage of requests with websites where port 80 redirects to port 443, which is extremely common now.

velocity patched_addr also ignores the other args provided, which means it caches results which are inappropriate for subsequent invocations.