decolua/9router · warning · Error

Invalid MITM router URL

Error message

Invalid MITM router URL

What it means

normalizeMitmRouterBaseUrlInput validates the mitmRouterBaseUrl field sent to the antigravity-mitm API. If the value is non-empty but cannot be parsed by the URL constructor (after trimming and stripping trailing slashes), it throws 'Invalid MITM router URL'. A separate error covers non-http(s) protocols; empty values fall back to the default http://localhost:20128.

Source

Thrown at src/app/api/cli-tools/antigravity-mitm/route.js:30

  isSudoPasswordRequired,
  initDbHooks,
} from "@/mitm/manager";
import { getSettings, updateSettings } from "@/lib/localDb";

initDbHooks(getSettings, updateSettings);

const DEFAULT_MITM_ROUTER_BASE = "http://localhost:20128";

function normalizeMitmRouterBaseUrlInput(input) {
  if (input == null || String(input).trim() === "") {
    return DEFAULT_MITM_ROUTER_BASE;
  }
  const t = String(input).trim().replace(/\/+$/, "");
  let u;
  try {
    u = new URL(t);
  } catch {
    throw new Error("Invalid MITM router URL");
  }
  if (u.protocol !== "http:" && u.protocol !== "https:") {
    throw new Error("MITM router URL must use http or https");
  }
  return t;
}

const isWin = process.platform === "win32";

function getPassword(provided) {
  return provided || getCachedPassword() || null;
}

function requiresSudoPassword(pwd) {
  return !isWin && !pwd && isSudoPasswordRequired();
}

function checkIsAdmin() {

View on GitHub (pinned to 90b52e06ff)

Solutions

  1. Include the scheme: use 'http://localhost:20128' rather than 'localhost:20128' — new URL() requires a protocol.
  2. Remove trailing paths/whitespace; the field expects a bare base URL (trailing slashes are stripped automatically).
  3. Leave the field empty to use the default http://localhost:20128 if you don't need a custom value.
  4. Ensure only http: or https: protocols are used — any other scheme yields the related protocol error.

Example fix

// before
mitmRouterBaseUrl: "localhost:20128"
// after
mitmRouterBaseUrl: "http://localhost:20128"
Defensive patterns

Strategy: validation

Validate before calling

function normalizeMitmRouterBaseUrlClient(input) {
  if (input == null || String(input).trim() === "") return "http://localhost:20128";
  const t = String(input).trim().replace(/\/+$/, "");
  let u;
  try { u = new URL(t); } catch { throw new Error("Invalid MITM router URL — include the scheme, e.g. http://localhost:20128"); }
  if (u.protocol !== "http:" && u.protocol !== "https:") throw new Error("MITM router URL must use http or https");
  return t;
}

Type guard

const isValidHttpUrl = (s) => { try { const u = new URL(String(s).trim()); return u.protocol === "http:" || u.protocol === "https:"; } catch { return false; } };

Try / catch

try {
  const res = await fetch("/api/cli-tools/antigravity-mitm", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ apiKey, sudoPassword, mitmRouterBaseUrl }) });
  const data = await res.json();
  if (!res.ok) throw new Error(data.error || `MITM start failed (HTTP ${res.status})`);
} catch (e) {
  if (/Invalid MITM router URL/.test(e.message)) showFieldError("mitmRouterBaseUrl", "Enter a full URL including scheme, e.g. http://localhost:20128");
  else showError(e.message);
}

Prevention

When it happens

Trigger: POST /api/cli-tools/antigravity-mitm with body { mitmRouterBaseUrl: '<unparseable string>' } — e.g. 'localhost:20128' (no scheme), 'http:/localhost', a value with embedded spaces or stray characters — causing new URL(t) to throw at route.js:30; the route returns 400 { error: 'Invalid MITM router URL' }.

Common situations: User typed 'localhost:20128' or a bare host:port without http:// into the MITM settings field; copy-pasted URL with trailing junk or hidden whitespace/newlines; accidentally passing a full tool URL or path instead of a base URL.

Related errors


AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30). Data as JSON: /api/errors/7b8ccb47338a57f5. Report an issue: GitHub.