mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-115197: Stop resolving host in urllib.request proxy bypass (GH-115210)
gh-115197: Stop resolving host in urllib.request proxy bypass (GH-115210)
Use of a proxy is intended to defer DNS for the hosts to the proxy itself, rather than a potential for information leak of the host doing DNS resolution itself for any reason. Proxy bypass lists are strictly name based. Most implementations of proxy support agree.
(cherry picked from commit c43b26d02e
)
Co-authored-by: Weii Wang <weii.wang@canonical.com>
This commit is contained in:
parent
91e680b85c
commit
dec637a953
3 changed files with 64 additions and 44 deletions
|
@ -14,10 +14,11 @@ import tempfile
|
|||
import subprocess
|
||||
|
||||
import urllib.request
|
||||
# The proxy bypass method imported below has logic specific to the OSX
|
||||
# proxy config data structure but is testable on all platforms.
|
||||
# The proxy bypass method imported below has logic specific to the
|
||||
# corresponding system but is testable on all platforms.
|
||||
from urllib.request import (Request, OpenerDirector, HTTPBasicAuthHandler,
|
||||
HTTPPasswordMgrWithPriorAuth, _parse_proxy,
|
||||
_proxy_bypass_winreg_override,
|
||||
_proxy_bypass_macosx_sysconf,
|
||||
AbstractDigestAuthHandler)
|
||||
from urllib.parse import urlparse
|
||||
|
@ -1483,6 +1484,30 @@ class HandlerTests(unittest.TestCase):
|
|||
self.assertEqual(req.host, "proxy.example.com:3128")
|
||||
self.assertEqual(req.get_header("Proxy-authorization"), "FooBar")
|
||||
|
||||
@unittest.skipUnless(os.name == "nt", "only relevant for Windows")
|
||||
def test_winreg_proxy_bypass(self):
|
||||
proxy_override = "www.example.com;*.example.net; 192.168.0.1"
|
||||
proxy_bypass = _proxy_bypass_winreg_override
|
||||
for host in ("www.example.com", "www.example.net", "192.168.0.1"):
|
||||
self.assertTrue(proxy_bypass(host, proxy_override),
|
||||
"expected bypass of %s to be true" % host)
|
||||
|
||||
for host in ("example.com", "www.example.org", "example.net",
|
||||
"192.168.0.2"):
|
||||
self.assertFalse(proxy_bypass(host, proxy_override),
|
||||
"expected bypass of %s to be False" % host)
|
||||
|
||||
# check intranet address bypass
|
||||
proxy_override = "example.com; <local>"
|
||||
self.assertTrue(proxy_bypass("example.com", proxy_override),
|
||||
"expected bypass of %s to be true" % host)
|
||||
self.assertFalse(proxy_bypass("example.net", proxy_override),
|
||||
"expected bypass of %s to be False" % host)
|
||||
for host in ("test", "localhost"):
|
||||
self.assertTrue(proxy_bypass(host, proxy_override),
|
||||
"expect <local> to bypass intranet address '%s'"
|
||||
% host)
|
||||
|
||||
@unittest.skipUnless(sys.platform == 'darwin', "only relevant for OSX")
|
||||
def test_osx_proxy_bypass(self):
|
||||
bypass = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue