Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Refuse non-http(s) navigation URLs before consulting DNS (SKY-13070) (#8051)
pedrohsdbcd68bdbbbc7c
diff --git a/skyvern/utils/url_validators.py b/skyvern/utils/url_validators.pyindex 716a66002..fee4e1808 100644--- a/skyvern/utils/url_validators.py+++ b/skyvern/utils/url_validators.py@@ -284,6 +284,10 @@ def _raise_if_best_effort_fetch_host_is_blocked(url: str) -> None:candidate = url.replace("\\", "/")try:parsed = urlsplit(candidate)+ # Non-http(s) schemes are already refused by the caller's parse error; resolving their+ # hosts would block the caller's event loop on DNS for a URL that gets refused anyway.+ if parsed.scheme and parsed.scheme not in ("http", "https"):+ returnif not parsed.scheme:parsed = urlsplit(f"https://{candidate}")host = parsed.hostnamediff --git a/tests/unit/test_url_validators.py b/tests/unit/test_url_validators.pyindex bed6e7b6e..c32aafb01 100644--- a/tests/unit/test_url_validators.py+++ b/tests/unit/test_url_validators.py@@ -3,7 +3,7 @@ import socketimport pytestfrom skyvern.config import settings-from skyvern.exceptions import BlockedHost, UnresolvableHost+from skyvern.exceptions import BlockedHost, SkyvernHTTPException, UnresolvableHostfrom skyvern.utils.url_validators import (encode_url,is_blocked_host,@@ -229,6 +229,17 @@ def test_validate_fetch_url_checks_blocked_host_when_url_is_too_long(assert type(exc_info.value) is BlockedHost[email protected]("url", ["ftp://public.example.test/file", "chrome://settings", "gopher://host/x"])+def test_validate_fetch_url_refuses_nonhttp_scheme_without_dns(monkeypatch: pytest.MonkeyPatch, url: str) -> None:+ def unexpected_dns(host: str, port: int | None, *args: object, **kwargs: object) -> list[object]:+ raise AssertionError("non-http(s) schemes must be refused before DNS is consulted")++ monkeypatch.setattr("skyvern.utils.url_validators.socket.getaddrinfo", unexpected_dns)++ with pytest.raises(SkyvernHTTPException):+ validate_fetch_url(url)++@pytest.mark.parametrize("blocked_host", ["169.254.169.254", "127.0.0.1", "10.0.0.5"])def test_validate_fetch_url_checks_blocked_host_behind_backslash_authority(blocked_host: str,