fix(mitm): forward passthrough traffic to the real requested host (#10479) (#10762)

Co-authored-by: Markus Hartung <mail@hartmark.se>
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-08-19 12:49:54 -03:00
committed by GitHub
parent 5d9ed144f4
commit 6b8307530f
3 changed files with 32 additions and 1 deletions

View File

@@ -0,0 +1 @@
- fix(mitm): forward passthrough traffic to the actual requested Host instead of misrouting every non-TARGET_HOSTS request to the hardcoded Antigravity sandbox host (#10479)

View File

@@ -318,7 +318,14 @@ function getTargetHost(req) {
const host = String(req.headers.host || "")
.split(":")[0]
.toLowerCase();
return TARGET_HOSTS.has(host) ? host : "daily-cloudcode-pa.sandbox.googleapis.com";
// #10479: the non-TARGET_HOSTS branch used to hardcode a fallback host — in
// the original Antigravity DNS-spoof flow, req.headers.host is always a
// TARGET_HOSTS member, so it was dead code. The passthrough() call path
// added for transparent-redirect/HTTP-proxy clients can reach ANY internet
// host, so the real requested Host header must always be forwarded, never
// a hardcoded default (which silently misrouted every non-TARGET_HOSTS
// request to an unrelated backend).
return host;
}
async function resolveTargetIP(targetHost) {

View File

@@ -0,0 +1,23 @@
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import url from "node:url";
const here = path.dirname(url.fileURLToPath(import.meta.url));
const serverPath = path.resolve(here, "../../src/mitm/server.cjs");
const src = fs.readFileSync(serverPath, "utf-8");
test("issue #10479: getTargetHost() must not reroute unknown/passthrough hosts to the hardcoded Antigravity default", () => {
const fnMatch = src.match(/function getTargetHost\(req\) \{[\s\S]*?\n\}/);
assert.ok(fnMatch, "getTargetHost() must exist in server.cjs");
const fnBody = fnMatch[0];
assert.doesNotMatch(
fnBody,
/:\s*"daily-cloudcode-pa\.sandbox\.googleapis\.com"/,
"getTargetHost() must not hardcode the Antigravity sandbox host as the " +
"fallback target for hosts outside TARGET_HOSTS — passthrough traffic " +
"for e.g. example.org must be forwarded to example.org, not to Google's " +
"Cloud Code API (issue #10479)"
);
});