Skip to content

Commit cd4b5ba

Browse files
committed
test: cover NAT64/IPv4-compatible embedded-IP SSRF blocking
1 parent 2295b1c commit cd4b5ba

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/unittests/tools/test_load_web_page.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,43 @@ def test_load_web_page_blocks_shared_address_space_urls(monkeypatch):
8585
mock_send.assert_not_called()
8686

8787

88+
def test_load_web_page_blocks_nat64_embedded_metadata_ip(monkeypatch):
89+
_clear_proxy_env(monkeypatch)
90+
mock_get = mock.Mock()
91+
monkeypatch.setattr(load_web_page_module.requests, 'get', mock_get)
92+
mock_send = mock.Mock()
93+
monkeypatch.setattr(load_web_page_module.HTTPAdapter, 'send', mock_send)
94+
95+
result = load_web_page(
96+
'http://[64:ff9b::169.254.169.254]/computeMetadata/v1/'
97+
)
98+
99+
assert (
100+
result
101+
== 'Failed to fetch url:'
102+
' http://[64:ff9b::169.254.169.254]/computeMetadata/v1/'
103+
)
104+
mock_get.assert_not_called()
105+
mock_send.assert_not_called()
106+
107+
108+
def test_load_web_page_blocks_ipv4_compatible_embedded_private_ip(monkeypatch):
109+
_clear_proxy_env(monkeypatch)
110+
mock_get = mock.Mock()
111+
monkeypatch.setattr(load_web_page_module.requests, 'get', mock_get)
112+
mock_send = mock.Mock()
113+
monkeypatch.setattr(load_web_page_module.HTTPAdapter, 'send', mock_send)
114+
115+
result = load_web_page('http://[::169.254.169.254]/latest/meta-data/')
116+
117+
assert (
118+
result
119+
== 'Failed to fetch url: http://[::169.254.169.254]/latest/meta-data/'
120+
)
121+
mock_get.assert_not_called()
122+
mock_send.assert_not_called()
123+
124+
88125
def test_load_web_page_blocks_private_hostname_targets(monkeypatch):
89126
_clear_proxy_env(monkeypatch)
90127
monkeypatch.setattr(

0 commit comments

Comments
 (0)