From f8026a7b39cc2def0b8a29198824f3ec17067d71 Mon Sep 17 00:00:00 2001 From: CloakHQ Date: Mon, 11 May 2026 21:02:58 +0200 Subject: [PATCH] chore: clean up GeoIP timeout follow-up (#213) Remove dead null checks, document CLOAKBROWSER_GEOIP_TIMEOUT_SECONDS env var, credit contributor. Fix review findings: - Use timeout-bounded resolve_proxy_exit_ip in _resolve_webrtc_args - Add missing timeout handler on tunneled HTTPS request in JS - Reject nan/inf in Python timeout parsing (parity with JS) - Recompute deadline after CONNECT succeeds in JS proxy tunnel --- README.md | 3 ++- cloakbrowser/browser.py | 9 +++------ cloakbrowser/geoip.py | 3 +++ js/src/geoip.ts | 13 ++++--------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 61da6a0..081a21e 100644 --- a/README.md +++ b/README.md @@ -570,6 +570,7 @@ Access the original un-patched Playwright page at `page._original` if you need r | `CLOAKBROWSER_DOWNLOAD_URL` | `cloakbrowser.dev` | Custom download URL for binary | | `CLOAKBROWSER_AUTO_UPDATE` | `true` | Set to `false` to disable background update checks | | `CLOAKBROWSER_SKIP_CHECKSUM` | `false` | Set to `true` to skip SHA-256 verification after download | +| `CLOAKBROWSER_GEOIP_TIMEOUT_SECONDS` | `5` | Max seconds for GeoIP resolution before continuing without it | ## Fingerprint Management @@ -1193,6 +1194,6 @@ Issues and PRs welcome. If something isn't working, [open an issue](https://gith - [@yahooguntu](https://github.com/yahooguntu) — persistent contexts - [@kitiho](https://github.com/kitiho) — null viewport fix - [@eofreternal](https://github.com/eofreternal) — humanConfig type fix, humanized method option types -- [@manaskarra](https://github.com/manaskarra) — iframe scope fix for humanized frame actions +- [@manaskarra](https://github.com/manaskarra) — iframe scope fix for humanized frame actions, GeoIP timeout guard - [@Youhai020616](https://github.com/Youhai020616) — SOCKS5 credential encoding logging - [@AlexTech314](https://github.com/AlexTech314) — AWS Lambda integration diff --git a/cloakbrowser/browser.py b/cloakbrowser/browser.py index 5d0865f..bb6b259 100644 --- a/cloakbrowser/browser.py +++ b/cloakbrowser/browser.py @@ -902,10 +902,7 @@ def maybe_resolve_geoip( exit_ip = resolve_proxy_exit_ip(proxy_url) return timezone, locale, exit_ip - geo_result = resolve_proxy_geo_with_ip(proxy_url) - if geo_result is None: - return timezone, locale, None - geo_tz, geo_locale, exit_ip = geo_result + geo_tz, geo_locale, exit_ip = resolve_proxy_geo_with_ip(proxy_url) if timezone is None: timezone = geo_tz if locale is None: @@ -937,8 +934,8 @@ def _resolve_webrtc_args( del args[idx] return args try: - from .geoip import _resolve_exit_ip - exit_ip = _resolve_exit_ip(proxy_url) + from .geoip import resolve_proxy_exit_ip + exit_ip = resolve_proxy_exit_ip(proxy_url) except Exception: logger.warning("Failed to resolve proxy exit IP for WebRTC spoofing; removing --fingerprint-webrtc-ip=auto") args = list(args) diff --git a/cloakbrowser/geoip.py b/cloakbrowser/geoip.py index 1ed550c..31f4262 100644 --- a/cloakbrowser/geoip.py +++ b/cloakbrowser/geoip.py @@ -12,6 +12,7 @@ from __future__ import annotations import ipaddress import logging +import math import os import socket import tempfile @@ -167,6 +168,8 @@ def _get_geoip_timeout_seconds() -> float: try: timeout = float(raw) except ValueError: + timeout = float("nan") + if not math.isfinite(timeout): logger.warning( "Invalid %s=%r; using %.1fs", GEOIP_TIMEOUT_ENV, diff --git a/js/src/geoip.ts b/js/src/geoip.ts index 0437727..b324223 100644 --- a/js/src/geoip.ts +++ b/js/src/geoip.ts @@ -232,9 +232,10 @@ async function resolveExitIp(proxyUrl: string, timeoutMs?: number): Promise { + const innerRemaining = remainingMs(deadline); const req = https.request( echoUrl, - { socket, timeout: Math.min(5_000, remaining ?? 5_000) } as any, + { socket, timeout: Math.min(5_000, innerRemaining ?? 5_000) } as any, (res) => { let data = ""; res.on("data", (chunk: Buffer) => (data += chunk.toString())); @@ -245,6 +246,7 @@ async function resolveExitIp(proxyUrl: string, timeoutMs?: number): Promise resolve(null)); + req.on("timeout", () => { req.destroy(); resolve(null); }); req.end(); }); @@ -374,14 +376,7 @@ export async function maybeResolveGeoip( return { timezone: options.timezone, locale: options.locale, exitIp }; } - const geoResult = await resolveProxyGeo(proxyUrl); - if (!geoResult) { - return { - timezone: options.timezone, - locale: options.locale, - }; - } - const { timezone: geoTz, locale: geoLocale, exitIp: geoExitIp } = geoResult; + const { timezone: geoTz, locale: geoLocale, exitIp: geoExitIp } = await resolveProxyGeo(proxyUrl); const exitIp = geoExitIp ?? undefined; return { timezone: options.timezone ?? geoTz ?? undefined,