codekingpro/portable-devtools
114k
1from http import cookiejar2 3 4_LOCALHOST = 'localhost'5_LOCALHOST_SUFFIX = '.localhost'6 7 8class HTTPieCookiePolicy(cookiejar.DefaultCookiePolicy):9 def return_ok_secure(self, cookie, request):10 """Check whether the given cookie is sent to a secure host."""11 12 is_secure_protocol = super().return_ok_secure(cookie, request)13 if is_secure_protocol:14 return True15 16 # The original implementation of this method only takes secure protocols17 # (e.g., https) into account, but the latest developments in modern browsers18 # (chrome, firefox) assume 'localhost' is also a secure location. So we19 # override it with our own strategy.20 return self._is_local_host(cookiejar.request_host(request))21 22 def _is_local_host(self, hostname):23 # Implements the static localhost detection algorithm in firefox.24 # <https://searchfox.org/mozilla-central/rev/d4d7611ee4dd0003b492b865bc5988a4e6afc985/netwerk/dns/DNS.cpp#205-218>25 return hostname == _LOCALHOST or hostname.endswith(_LOCALHOST_SUFFIX)26 