Skip to content

Caching of getaddrinfo pins port #2

@jayvdb

Description

@jayvdb
>>> 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions