Skip to content

Commit

Permalink
Remove the contains_private_ip function
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout Feys committed Aug 30, 2024
1 parent dc7dea8 commit 2e648d9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 231 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Exports is_redirect_to_private_ip"""

from aikido_firewall.helpers.get_port_from_url import get_port_from_url
from .contains_private_ip_address import contains_private_ip_address
from .get_redirect_origin import get_redirect_origin
from .find_hostname_in_context import find_hostname_in_context

Expand All @@ -18,7 +17,7 @@ def is_redirect_to_private_ip(hostname, context, port):
- The redirect origin, so the user-supplied hostname and port that caused the first redirect,
is found in the context of the incoming request
"""
if context.outgoing_req_redirects and contains_private_ip_address(hostname):
if context.outgoing_req_redirects:
redirect_origin = get_redirect_origin(
context.outgoing_req_redirects, hostname, port
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,8 @@ def test_is_redirect_to_private_ip_not_private_ip():
},
]

with MagicMock() as mock_contains_private_ip_address:
mock_contains_private_ip_address.return_value = False
with pytest.MonkeyPatch.context() as mp:
mp.setattr(
"aikido_firewall.vulnerabilities.ssrf.contains_private_ip_address",
mock_contains_private_ip_address,
)

result = is_redirect_to_private_ip("example.com", context, 443)
assert result is None
result = is_redirect_to_private_ip("example.com", context, 443)
assert result is None


def test_is_redirect_to_private_ip_redirect_origin_not_found():
Expand All @@ -66,16 +58,11 @@ def test_is_redirect_to_private_ip_redirect_origin_not_found():
},
]

with MagicMock() as mock_contains_private_ip_address, MagicMock() as mock_get_redirect_origin:
with MagicMock() as mock_get_redirect_origin:

mock_contains_private_ip_address.return_value = True
mock_get_redirect_origin.return_value = None

with pytest.MonkeyPatch.context() as mp:
mp.setattr(
"aikido_firewall.vulnerabilities.ssrf.contains_private_ip_address",
mock_contains_private_ip_address,
)
mp.setattr(
"aikido_firewall.vulnerabilities.ssrf.get_redirect_origin",
mock_get_redirect_origin,
Expand All @@ -94,19 +81,14 @@ def test_is_redirect_to_private_ip_hostname_not_found_in_context():
},
]

with MagicMock() as mock_contains_private_ip_address, MagicMock() as mock_get_redirect_origin, MagicMock() as mock_find_hostname_in_context:
with MagicMock() as mock_get_redirect_origin, MagicMock() as mock_find_hostname_in_context:

mock_contains_private_ip_address.return_value = True
mock_get_redirect_origin.return_value = MagicMock(
hostname="example.com", port=80
)
mock_find_hostname_in_context.return_value = False

with pytest.MonkeyPatch.context() as mp:
mp.setattr(
"aikido_firewall.vulnerabilities.ssrf.contains_private_ip_address",
mock_contains_private_ip_address,
)
mp.setattr(
"aikido_firewall.vulnerabilities.ssrf.get_redirect_origin",
mock_get_redirect_origin,
Expand Down

0 comments on commit 2e648d9

Please sign in to comment.