v3.6.4: reject transparent proxies (echo == own network), Edge startup-boost policy + survivor-proof restart so proxy flags always apply, deploy script hardening - browser-side routing proven at proxy exit
This commit is contained in:
@@ -573,12 +573,23 @@ async function echoLadder(hops) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
let directEgress;
|
||||
async function directEgressOf() {
|
||||
// node fetch never reads HTTP_PROXY/v2ray — this is the machine's true exit.
|
||||
if (directEgress === undefined) {
|
||||
directEgress = null;
|
||||
try { const r = await fetch('http://checkip.amazonaws.com/', { signal: AbortSignal.timeout(7000) }); directEgress = (await r.text()).trim().split(/\s/)[0] || null; } catch { /* offline */ }
|
||||
}
|
||||
return directEgress;
|
||||
}
|
||||
async function probeCandidate(h) {
|
||||
const t0 = Date.now();
|
||||
const e = await echoLadder([h]);
|
||||
return e
|
||||
? { ok: true, ip: e.ip, country: e.country, as: e.org, ms: Date.now() - t0 }
|
||||
: { ok: false, reason: 'no echo (dead or blocking)', ms: Date.now() - t0 };
|
||||
const [e, own] = await Promise.all([echoLadder([h]), directEgressOf()]);
|
||||
if (!e) return { ok: false, reason: 'no echo (dead or blocking)', ms: Date.now() - t0 };
|
||||
if (own && (e.ip === own || e.ip.startsWith(own.split('.').slice(0, 2).join('.') + '.'))) {
|
||||
return { ok: false, reason: `transparent (exit ${e.ip} is your own network — routing through it changes nothing)`, ms: Date.now() - t0 };
|
||||
}
|
||||
return { ok: true, ip: e.ip, country: e.country, as: e.org, ms: Date.now() - t0 };
|
||||
}
|
||||
|
||||
const pipeBoth = (a, b) => {
|
||||
@@ -667,12 +678,26 @@ async function egressVia(hops) {
|
||||
async function restartSession() {
|
||||
const la = session && session.launchArgs ? session.launchArgs : null;
|
||||
if (!session || session.attached || !la) return false;
|
||||
const { child, ws } = session;
|
||||
const { child, ws, kind } = session;
|
||||
session = null;
|
||||
try { ws.close(); } catch { /* gone */ }
|
||||
if (child && child.exitCode === null) child.kill();
|
||||
const t0 = Date.now();
|
||||
while (await probePort(la.port || effectivePort(la)) && Date.now() - t0 < 6000) await new Promise((r) => setTimeout(r, 500));
|
||||
const port = la.port || effectivePort(la);
|
||||
const waitFree = async (ms) => {
|
||||
const t0 = Date.now();
|
||||
while (await probePort(port) && Date.now() - t0 < ms) await new Promise((r) => setTimeout(r, 400));
|
||||
return !(await probePort(port));
|
||||
};
|
||||
if (!(await waitFree(6000))) {
|
||||
// A survivor browser (Edge startup-boost, profile handoff, leftover window)
|
||||
// retook the port without our new flags — a fresh spawn would merge into it
|
||||
// and silently lose proxy routing. Kill instances of this browser kind
|
||||
// (same semantics as relaunch:true; logins survive, windows reopen).
|
||||
const exe = kind === 'firefox' ? 'firefox' : kind === 'chrome' ? 'chrome' : 'msedge';
|
||||
const killCmd = process.platform === 'win32' ? `taskkill /IM ${exe}.exe /F` : `pkill -9 -x ${exe}`;
|
||||
await new Promise((r) => exec(killCmd, () => r()));
|
||||
if (!(await waitFree(8000))) return false;
|
||||
}
|
||||
await doLaunch(la);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user