Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix(security): fold IDNA label separators before IPv4 classification
Saurav Panda7d061a0327d6
diff --git a/browser_use/browser/watchdogs/security_watchdog.py b/browser_use/browser/watchdogs/security_watchdog.pyindex 603f3967d..ebb435582 100644--- a/browser_use/browser/watchdogs/security_watchdog.py+++ b/browser_use/browser/watchdogs/security_watchdog.py@@ -185,6 +185,16 @@ class SecurityWatchdog(BaseWatchdog):except Exception:pass+ # Fold IDNA label separators to ASCII `.`. Per RFC 3490 / UTS46 four+ # code points act as label separators in IDNA processing: `.` (U+002E),+ # `。` (U+3002), `.` (U+FF0E), `。` (U+FF61). NFKC handles U+FF0E only+ # and maps U+FF61 → U+3002 (still ideographic), leaving the IPv4 parser+ # unable to match. WHATWG URL parsing folds all four to `.` before+ # resolution, so we must do the same.+ for _dot in ('。', '。'):+ if _dot in bare:+ bare = bare.replace(_dot, '.')+# Standard dotted-quad IPv4 and full IPv6.try:ipaddress.ip_address(bare)diff --git a/tests/ci/security/test_ip_blocking.py b/tests/ci/security/test_ip_blocking.pyindex d76c99ba0..e85f3b69e 100644--- a/tests/ci/security/test_ip_blocking.py+++ b/tests/ci/security/test_ip_blocking.py@@ -650,3 +650,26 @@ class TestNonStandardIPv4Representations:assert watchdog._is_ip_address('xn--caf-dma.example') is Falseassert watchdog._is_ip_address('日本.example') is Falseassert watchdog._is_ip_address('xn--wgv71a.example') is False++ def test_idna_dot_separators_blocked(self):+ """Per RFC 3490 / UTS46, four code points act as label separators in+ IDNA processing — `.` (U+002E), `。` (U+3002 IDEOGRAPHIC FULL STOP),+ `.` (U+FF0E FULLWIDTH FULL STOP), `。` (U+FF61 HALFWIDTH IDEOGRAPHIC+ FULL STOP). WHATWG URL parsing maps all four to `.` before resolution,+ so `http://127。0。0。1/` etc. reach 127.0.0.1.++ NFKC alone is insufficient — it maps U+FF0E → U+002E and U+FF61 →+ U+3002, but leaves U+3002 (the most common one) untouched. Classifier+ must additionally fold U+3002 and U+FF61 to U+002E before IP parsing.+ """+ watchdog = self._watchdog()+ # All four dot variants must result in the IP being blocked.+ assert watchdog._is_url_allowed('http://127。0。0。1/') is False # U+3002+ assert watchdog._is_url_allowed('http://127。0。0。1/') is False # U+FF61+ assert watchdog._is_url_allowed('http://127.0.0.1/') is False # U+FF0E+ # Combined with circled-digit normalization.+ assert watchdog._is_url_allowed('http://①②⑦。⓪。⓪。①/') is False+ # Direct classifier checks.+ assert watchdog._is_ip_address('127。0。0。1') is True+ assert watchdog._is_ip_address('127。0。0。1') is True+ assert watchdog._is_ip_address('127.0.0.1') is True