Repository navigation
fix(mitm): add IPv6 DNS redirect, modular antigravity target, improved logging #2514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,10 +13,12 @@ function getDataDir() { | |
| } | ||
|
|
||
| // Configuration | ||
| // Keep in sync with src/mitm/targets/antigravity.ts | ||
| const TARGET_HOSTS = new Set([ | ||
| "daily-cloudcode-pa.sandbox.googleapis.com", | ||
| "daily-cloudcode-pa.googleapis.com", | ||
| "cloudcode-pa.googleapis.com", | ||
| "autopush-cloudcode-pa.sandbox.googleapis.com", | ||
| ]); | ||
| const parsedLocalPort = Number.parseInt(process.env.MITM_LOCAL_PORT || "443", 10); | ||
| const LOCAL_PORT = | ||
|
|
@@ -288,33 +290,42 @@ const server = https.createServer(sslOptions, async (req, res) => { | |
| writeStats(); | ||
|
|
||
| const bodyBuffer = await collectBodyRaw(req); | ||
| const host = String(req.headers.host || "").split(":")[0].toLowerCase(); | ||
| const model = bodyBuffer.length > 0 ? extractModel(bodyBuffer) : null; | ||
|
|
||
| console.log(`[MITM] ${req.method} ${host}${req.url} | body: ${bodyBuffer.length}B | model: ${model || "N/A"}`); | ||
|
|
||
| // Save request log if enabled | ||
| if (bodyBuffer.length > 0) saveRequestLog(req.url, bodyBuffer); | ||
|
|
||
| // Anti-loop: requests from OmniRoute bypass interception | ||
| if (req.headers["x-omniroute-source"] === "omniroute") { | ||
| console.log(`[MITM] → PASSTHROUGH (OmniRoute source loop)`); | ||
| return passthrough(req, res, bodyBuffer); | ||
| } | ||
|
|
||
| if (!TARGET_HOSTS.has(host)) { | ||
| console.log(`[MITM] → PASSTHROUGH (host ${host} not in target list)`); | ||
| return passthrough(req, res, bodyBuffer); | ||
| } | ||
|
|
||
| const isChatRequest = CHAT_URL_PATTERNS.some((p) => req.url.includes(p)); | ||
|
|
||
| if (!isChatRequest) { | ||
| console.log(`[MITM] → PASSTHROUGH (URL ${req.url} does not match chat patterns)`); | ||
| return passthrough(req, res, bodyBuffer); | ||
| } | ||
|
Comment on lines
310
to
315
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| const model = extractModel(bodyBuffer); | ||
| const mappedModel = getMappedModel(model); | ||
|
|
||
| if (!mappedModel) { | ||
| console.log(`[MITM] → PASSTHROUGH (model "${model}" has no MITM alias mapping)`); | ||
| return passthrough(req, res, bodyBuffer); | ||
| } | ||
|
|
||
| stats.interceptedRequests++; | ||
| stats.lastInterceptAt = new Date().toISOString(); | ||
| writeStats(); | ||
|
|
||
| console.log(`🔀 ${model} → ${mappedModel}`); | ||
| console.log(`[MITM] INTERCEPTED ${model} → ${mappedModel}`); | ||
| return intercept(req, res, bodyBuffer, mappedModel); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| export interface MitmTarget { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the repository style guide (Rule 9), changes to production code in References
|
||
| id: string; | ||
| name: string; | ||
| description: string; | ||
| targetHost: string; | ||
| targetPort: number; | ||
| localPort: number; | ||
| userAgentPattern: string | null; | ||
| apiEndpoints: string[]; | ||
| authHeader: string; | ||
| additionalHosts?: string[]; | ||
| instructions: string[]; | ||
| referenceIde?: string; | ||
| } | ||
|
|
||
| export const ANTIGRAVITY_MITM_PROFILE: MitmTarget = { | ||
| id: "antigravity", | ||
| name: "Antigravity IDE", | ||
| description: | ||
| "Intercepts Antigravity IDE requests to cloudcode-pa.googleapis.com and routes them through OmniRoute.", | ||
| targetHost: "daily-cloudcode-pa.googleapis.com", | ||
| targetPort: 443, | ||
| localPort: 443, | ||
| userAgentPattern: null, | ||
| apiEndpoints: [ | ||
| "/v1internal:generateContent", | ||
| "/v1internal:streamGenerateContent", | ||
| "/v1internal:loadCodeAssist", | ||
| "/v1internal:onboardUser", | ||
| ], | ||
| authHeader: "authorization", | ||
| additionalHosts: ["cloudcode-pa.googleapis.com", "daily-cloudcode-pa.sandbox.googleapis.com"], | ||
| instructions: [ | ||
| "1. Install OmniRoute's root certificate", | ||
| "2. Start the MITM proxy via Dashboard or CLI", | ||
| "3. Configure model mappings in Dashboard → CLI Tools → Antigravity", | ||
| "4. Open Antigravity IDE — API calls will be routed through OmniRoute", | ||
| ], | ||
| }; | ||
|
Comment on lines
+16
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
DNS_ENTRIESarray is constructed using a single hardcodedTARGET_HOST. This is inconsistent with the goal of a modular target configuration. Since theANTIGRAVITY_MITM_PROFILEnow includesadditionalHosts(e.g.,cloudcode-pa.googleapis.com), traffic to those domains will not be redirected to the MITM proxy, causing them to bypass interception. The DNS configuration should be updated to handle all hosts defined in the active profile.