Skip to content

Commit 5996c22

Browse files
committed
test(e2e): update SSRF-3 and SSRF-6 for implicit allowed_ips behavior
SSRF-6: Private IP with literal IP host now gets implicit allowed_ips from PR #570, so CONNECT returns 200 instead of 403. SSRF-3: Loopback is still blocked but via the always-blocked path (implicit allowed_ips is synthesized, then resolve_and_check_allowed_ips catches it). Log message says 'always-blocked' instead of 'internal address'.
1 parent 4318fe3 commit 5996c22

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

e2e/python/test_sandbox_policy.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,14 @@ def test_ssrf_blocks_metadata_endpoint_despite_policy_allow(
607607
assert "403" in result.stdout
608608

609609

610-
def test_ssrf_log_shows_internal_address_block(
610+
def test_ssrf_log_shows_blocked_address(
611611
sandbox: Callable[..., Sandbox],
612612
) -> None:
613-
"""SSRF-3: Proxy log includes 'internal address' reason when SSRF check fires."""
613+
"""SSRF-3: Proxy log includes block reason when SSRF check fires.
614+
615+
Loopback addresses are always-blocked even with implicit allowed_ips.
616+
The log should show 'always-blocked' for 127.0.0.1.
617+
"""
614618
policy = _base_policy(
615619
network_policies={
616620
"internal": sandbox_pb2.NetworkPolicyRule(
@@ -629,8 +633,8 @@ def test_ssrf_log_shows_internal_address_block(
629633
log_result = sb.exec_python(_read_openshell_log())
630634
assert log_result.exit_code == 0, log_result.stderr
631635
log = log_result.stdout
632-
assert "internal address" in log.lower(), (
633-
f"Expected 'internal address' in proxy log, got:\n{log}"
636+
assert "always-blocked" in log.lower(), (
637+
f"Expected 'always-blocked' in proxy log, got:\n{log}"
634638
)
635639

636640

@@ -716,16 +720,21 @@ def test_ssrf_allowed_ips_hostless_permits_private_ip(
716720
)
717721

718722

719-
def test_ssrf_private_ip_blocked_without_allowed_ips(
723+
def test_ssrf_private_ip_allowed_with_literal_ip_host(
720724
sandbox: Callable[..., Sandbox],
721725
) -> None:
722-
"""SSRF-6: Private IP blocked when endpoint has no allowed_ips (default)."""
726+
"""SSRF-6: Private IP allowed when policy host is a literal IP address.
727+
728+
When the policy endpoint host is a literal IP, the user has explicitly
729+
declared intent. The proxy synthesizes an implicit allowed_ips entry,
730+
so the CONNECT succeeds (200) even without explicit allowed_ips.
731+
"""
723732
policy = _base_policy(
724733
network_policies={
725734
"internal": sandbox_pb2.NetworkPolicyRule(
726735
name="internal",
727736
endpoints=[
728-
# No allowed_ips — private IP should be blocked
737+
# No allowed_ips — but host is a literal IP, so implicit
729738
sandbox_pb2.NetworkEndpoint(host="10.200.0.1", port=19999),
730739
],
731740
binaries=[sandbox_pb2.NetworkBinary(path="/**")],
@@ -736,8 +745,8 @@ def test_ssrf_private_ip_blocked_without_allowed_ips(
736745
with sandbox(spec=spec, delete_on_exit=True) as sb:
737746
result = sb.exec_python(_proxy_connect(), args=("10.200.0.1", 19999))
738747
assert result.exit_code == 0, result.stderr
739-
assert "403" in result.stdout, (
740-
"Expected private IP to be blocked without allowed_ips"
748+
assert "200" in result.stdout, (
749+
f"Expected 200 for literal IP host, got: {result.stdout}"
741750
)
742751

743752

0 commit comments

Comments
 (0)