Skip to content

Quickly sandbox your AI agent.

Python

Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization'

Tyler Payne64635b502564
diff --git a/tests/integration/network/unrestricted/test_unrestricted.py b/tests/integration/network/unrestricted/test_unrestricted.py
index d619c6f..4cbad93 100644
--- a/tests/integration/network/unrestricted/test_unrestricted.py
+++ b/tests/integration/network/unrestricted/test_unrestricted.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
+from urllib.parse import urlsplit
import pytest
@@ -50,10 +51,21 @@ class TestUnrestrictedNetwork:
# getent should succeed if DNS is working
assert result.exit_code == 0, f"DNS resolution failed: {result.stderr}"
- # Parse getent output and require google.com as a hostname token,
- # not merely a substring at an arbitrary position.
+ # Parse getent output and require google.com (or subdomain) as a
+ # hostname token with proper host-boundary validation.
lines = [line.split() for line in result.stdout.splitlines() if line.strip()]
- has_google_host = any(len(fields) >= 2 and "google.com" in fields[1:] for fields in lines)
+ has_google_host = False
+ for fields in lines:
+ if len(fields) < 2:
+ continue
+ for token in fields[1:]:
+ normalized = token.rstrip(".").lower()
+ host = urlsplit(f"//{normalized}").hostname
+ if host and (host == "google.com" or host.endswith(".google.com")):
+ has_google_host = True
+ break
+ if has_google_host:
+ break
assert has_google_host, "Expected google.com hostname token in getent output"
@pytest.mark.asyncio