mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2026-04-28 11:40:32 +00:00
25 lines
597 B
Python
25 lines
597 B
Python
"""Localhost URL detection for cloud browser sessions."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
_LOCALHOST_HOSTNAMES = frozenset(
|
|
{
|
|
"localhost",
|
|
"127.0.0.1",
|
|
"0.0.0.0", # noqa: S104 — detection, not binding
|
|
"::1",
|
|
"[::1]",
|
|
}
|
|
)
|
|
|
|
|
|
def is_localhost_url(url: str) -> bool:
|
|
"""Return True if *url* points to a loopback address."""
|
|
try:
|
|
parsed = urlparse(url)
|
|
hostname = (parsed.hostname or "").lower()
|
|
return hostname in _LOCALHOST_HOSTNAMES
|
|
except Exception:
|
|
return False
|