Skip to content

Stealth Chromium that passes every bot detection test. Drop-in Playwright replacement with source-level fingerprint patches. 50+ tests passed.

fix(geoip): accept a raw % in proxy credentials in the JS exit-IP lookup (#670)

Mert Kaya1d96c538cbd4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index acec5d5..586fcc6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Changes are tagged: **[wrapper]** for Python/JS wrapper, **[binary]** for Chromi
## [Unreleased]
+- **[wrapper]** `geoip` and `--fingerprint-webrtc-ip=auto` work with a proxy URL that has a raw `%` in its credentials, like `http://user:100%sure@host:8080`. The browser already accepted it, but the exit-IP lookup threw `URI malformed` for a SOCKS5 proxy and never reached an HTTP proxy. JavaScript
- **[wrapper]** `clear-cache` (`clear_cache()`, JS `clearCache()`, .NET `Download.ClearCache()`) removes only the cached browser builds. It deleted the whole `~/.cloakbrowser` folder, including the key saved by `login`, so the next launch failed with exit 77 until you logged in again. Python, JavaScript, and .NET
- **[wrapper]** `cloakserve`: `geoip=true` now works without a proxy and sets the timezone and locale from the machine's public IP (#658)
- **[wrapper]** `cloakserve`: the GeoIP lookup runs off the event loop, so other connected clients no longer stall while a `geoip=true` launch resolves its timezone and locale
diff --git a/js/src/geoip.ts b/js/src/geoip.ts
index af7e21d..8d6e730 100644
--- a/js/src/geoip.ts
+++ b/js/src/geoip.ts
@@ -216,6 +216,18 @@ const IP_ECHO_URLS = [
"https://ifconfig.me/ip",
];
+/**
+ * Parse a proxy URL, escaping a raw "%" in its credentials (e.g. a password
+ * like "100%sure", which the browser path accepts) so decodeURIComponent, ours
+ * and socks-proxy-agent's, does not throw on it.
+ */
+function parseProxyUrl(proxyUrl: string): URL {
+ const url = new URL(proxyUrl);
+ url.username = url.username.replace(/%(?![0-9A-Fa-f]{2})/g, "%25");
+ url.password = url.password.replace(/%(?![0-9A-Fa-f]{2})/g, "%25");
+ return url;
+}
+
async function resolveExitIp(proxyUrl: string | null | undefined, timeoutMs?: number): Promise<string | null> {
const deadline = timeoutMs && timeoutMs > 0 ? performance.now() + timeoutMs : null;
@@ -254,7 +266,7 @@ async function resolveExitIp(proxyUrl: string | null | undefined, timeoutMs?: nu
return null;
}
const { default: https } = await import("node:https");
- const agent = new SocksProxyAgent(proxyUrl);
+ const agent = new SocksProxyAgent(parseProxyUrl(proxyUrl));
for (const echoUrl of IP_ECHO_URLS) {
const remaining = remainingMs(deadline);
@@ -285,7 +297,7 @@ async function resolveExitIp(proxyUrl: string | null | undefined, timeoutMs?: nu
try {
const { default: http } = await import("node:http");
const { default: https } = await import("node:https");
- const proxyUrlObj = new URL(proxyUrl);
+ const proxyUrlObj = parseProxyUrl(proxyUrl);
for (const echoUrl of IP_ECHO_URLS) {
const remaining = remainingMs(deadline);
diff --git a/js/tests/geoip.test.ts b/js/tests/geoip.test.ts
index 75d9ce8..7cc97ce 100644
--- a/js/tests/geoip.test.ts
+++ b/js/tests/geoip.test.ts
@@ -115,6 +115,51 @@ describe("maybeResolveGeoip", () => {
}
});
+ it("sends CONNECT for a proxy URL with a raw % in the password", async () => {
+ const authorizationHeaders: Array<string | undefined> = [];
+ const sockets = new Set<Stream.Duplex>();
+ const proxy = http.createServer();
+ proxy.on("connect", (request, socket) => {
+ sockets.add(socket);
+ socket.once("close", () => sockets.delete(socket));
+ authorizationHeaders.push(request.headers["proxy-authorization"]);
+ socket.end("HTTP/1.1 407 Proxy Authentication Required\r\nContent-Length: 0\r\n\r\n");
+ });
+ await new Promise<void>((resolve) => proxy.listen(0, "127.0.0.1", resolve));
+ const { port } = proxy.address() as { port: number };
+ process.env.CLOAKBROWSER_GEOIP_TIMEOUT_SECONDS = "0.2";
+
+ try {
+ await maybeResolveGeoip({
+ geoip: true,
+ timezone: "America/New_York",
+ locale: "en-US",
+ proxy: `http://user:100%[email protected]:${port}`,
+ });
+ } finally {
+ for (const socket of sockets) socket.destroy();
+ await new Promise<void>((resolve) => proxy.close(() => resolve()));
+ }
+
+ expect(authorizationHeaders).not.toHaveLength(0);
+ expect(authorizationHeaders[0]).toBe(
+ "Basic " + Buffer.from("user:100%sure").toString("base64"),
+ );
+ });
+
+ it("does not throw for a SOCKS5 proxy URL with a raw % in the password", async () => {
+ process.env.CLOAKBROWSER_GEOIP_TIMEOUT_SECONDS = "0.2";
+ // Nothing listens on port 9: the lookup fails quietly instead of throwing URIError.
+ await expect(
+ maybeResolveGeoip({
+ geoip: true,
+ timezone: "America/New_York",
+ locale: "en-US",
+ proxy: "socks5://user:100%[email protected]:9",
+ }),
+ ).resolves.toEqual({ timezone: "America/New_York", locale: "en-US", exitIp: undefined });
+ });
+
it("does not apply the GeoIP resolution timeout to first-use database download", async () => {
const cacheDir = fs.mkdtempSync(path.join(os.tmpdir(), "cloak-geoip-download-"));
tempDirs.push(cacheDir);