-
Notifications
You must be signed in to change notification settings - Fork 1
π‘οΈ Sentinel: [HIGH] Fix SSRF protection to explicitly block link-local IPs #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1075,6 +1075,8 @@ def _is_safe_ip(ip: ipaddress.IPv4Address | ipaddress.IPv6Address) -> bool: | |
| return False | ||
| if ip.is_loopback: | ||
| return False | ||
| if ip.is_link_local: | ||
| return False | ||
|
Comment on lines
1076
to
+1079
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if isinstance(ip, ipaddress.IPv6Address) and ip.ipv4_mapped: | ||
| return _is_safe_ip(ip.ipv4_mapped) | ||
| if isinstance(ip, ipaddress.IPv4Address) and ip in _CGNAT_NETWORK: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import os | ||
| import socket | ||
| import sys | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| # Add root to path to import main | ||
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
|
||
| import main | ||
|
|
||
| class TestSSRFLinkLocal(unittest.TestCase): | ||
| def test_domain_resolving_to_link_local_ip(self): | ||
| """ | ||
| Test that a domain resolving to a link-local IP (169.254.169.254) is blocked. | ||
| """ | ||
| with patch("socket.getaddrinfo") as mock_getaddrinfo: | ||
| # Simulate resolving to AWS metadata service IP | ||
| mock_getaddrinfo.return_value = [ | ||
| (socket.AF_INET, socket.SOCK_STREAM, 6, "", ("169.254.169.254", 443)) | ||
| ] | ||
|
|
||
| url = "https://metadata.example.com/config.json" | ||
| result = main.validate_folder_url(url) | ||
| self.assertFalse(result, "Should block domain resolving to link-local IP") | ||
|
Comment on lines
+23
to
+25
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_is_safe_ipchecksip.is_loopbacktwice (once earlier and again here). The second check is redundant and makes the blocklist logic harder to audit; please remove the duplicate conditional to keep the security checks unambiguous.