Skip to content

Commit 79c0e49

Browse files
authored
Merge pull request #908 from elhoim/fix/html-to-markdown-ssrf-blocked-ranges
[critical] fix: [html_to_markdown] block unspecified, shared, ULA and link-local ranges in the URL safety check
2 parents ec4fce7 + 98a1c2c commit 79c0e49

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎misp_modules/modules/expansion/html_to_markdown.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@
2828

2929

3030
BLOCKED_RANGES = [
31+
ipaddress.ip_network("0.0.0.0/8"),
3132
ipaddress.ip_network("127.0.0.0/8"),
3233
ipaddress.ip_network("10.0.0.0/8"),
34+
ipaddress.ip_network("100.64.0.0/10"),
3335
ipaddress.ip_network("172.16.0.0/12"),
3436
ipaddress.ip_network("192.168.0.0/16"),
3537
ipaddress.ip_network("169.254.0.0/16"),
38+
ipaddress.ip_network("::/128"),
3639
ipaddress.ip_network("::1/128"),
40+
ipaddress.ip_network("fc00::/7"),
41+
ipaddress.ip_network("fe80::/10"),
3742
]
3843
MAX_REDIRECTS = 10
3944

‎tests/test_html_to_markdown.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ def test_blocks_hostnames_resolving_to_ipv4_mapped_blocked_addresses(self):
4343
):
4444
self.assertFalse(is_safe_url("http://example.test/"))
4545

46+
def test_blocks_unspecified_shared_ula_and_link_local_literals(self):
47+
blocked_urls = (
48+
"http://0.0.0.0/",
49+
"http://100.64.0.1/",
50+
"http://[::]/",
51+
"http://[fc00::1]/",
52+
"http://[fd12:3456::1]/",
53+
"http://[fe80::1]/",
54+
"http://[::ffff:0.0.0.0]/",
55+
"http://[::ffff:100.64.0.1]/",
56+
)
57+
58+
for url in blocked_urls:
59+
with self.subTest(url=url):
60+
self.assertFalse(is_safe_url(url))
61+
62+
def test_blocks_hostnames_resolving_to_ula_addresses(self):
63+
with patch(
64+
"misp_modules.modules.expansion.html_to_markdown.socket.getaddrinfo",
65+
return_value=[(None, None, None, None, ("fd00::1", 0, 0, 0))],
66+
):
67+
self.assertFalse(is_safe_url("http://example.test/"))
68+
4669
def test_rejects_url_without_hostname(self):
4770
self.assertFalse(is_safe_url("http:///missing-host"))
4871

0 commit comments

Comments
 (0)