From 7c7bedfa5d378197573d1470601186f256e73267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Mon, 22 Jul 2019 15:25:21 +0300 Subject: [PATCH] Fix server crash on request.server_port when bound to IPv6. If no X-Forwarded-Port nor Host headers are present, Sanic uses "sockname" to determine the port. This expected (host, port) tuple to be returned but for IPv6 a 4-tuple is returned instead. Changed code so that port is picked up in either case. Handling of "peername" was already correct in this regard. _get_address and server_port both still return incorrect data or crash for other socket types (e.g unix). Socket type should checked before any queries. --- sanic/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/request.py b/sanic/request.py index 9c87efd6..285333c7 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -388,7 +388,7 @@ class Request(dict): if forwarded_port: return int(forwarded_port) else: - _, port = self.transport.get_extra_info("sockname") + port = self.transport.get_extra_info("sockname")[1] return port @property