{"record":{"id":"0d2e42bf799ac374","repo":"decolua/9router","slug":"mitm-router-url-must-use-http-or-https","errorCode":null,"errorMessage":"MITM router URL must use http or https","messagePattern":"MITM router URL must use http or https","errorType":"validation","errorClass":"Error","httpStatus":500,"severity":"error","filePath":"src/app/api/cli-tools/antigravity-mitm/route.js","lineNumber":33,"sourceCode":"import { getSettings, updateSettings } from \"@/lib/localDb\";\n\ninitDbHooks(getSettings, updateSettings);\n\nconst DEFAULT_MITM_ROUTER_BASE = \"http://localhost:20128\";\n\nfunction normalizeMitmRouterBaseUrlInput(input) {\n  if (input == null || String(input).trim() === \"\") {\n    return DEFAULT_MITM_ROUTER_BASE;\n  }\n  const t = String(input).trim().replace(/\\/+$/, \"\");\n  let u;\n  try {\n    u = new URL(t);\n  } catch {\n    throw new Error(\"Invalid MITM router URL\");\n  }\n  if (u.protocol !== \"http:\" && u.protocol !== \"https:\") {\n    throw new Error(\"MITM router URL must use http or https\");\n  }\n  return t;\n}\n\nconst isWin = process.platform === \"win32\";\n\nfunction getPassword(provided) {\n  return provided || getCachedPassword() || null;\n}\n\nfunction requiresSudoPassword(pwd) {\n  return !isWin && !pwd && isSudoPasswordRequired();\n}\n\nfunction checkIsAdmin() {\n  if (isWin) {\n    try {\n      require(\"child_process\").execSync(\"net session >nul 2>&1\", { windowsHide: true });","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/app/api/cli-tools/antigravity-mitm/route.js#L15-L51","documentation":"normalizeMitmRouterBaseUrlInput validates a user-supplied MITM router base URL before it is used by the antigravity MITM proxy route. After parsing the input with new URL(), it rejects any URL whose protocol is neither http: nor https:. This guards the proxy against invalid schemes like file:, ws:, or ftp: which fetch/upstream routing cannot handle.","triggerScenarios":"POSTing to /api/cli-tools/antigravity-mitm with a routerUrl whose scheme is not http/https, e.g. 'ftp://host:20128', 'localhost:20128' parsed with a stray scheme, or a URL like 'file:///etc/passwd'.","commonSituations":"Users paste a router URL from docs including a typo'd scheme (e.g. 'tcp://'), or omit '//' so the URL parser assigns an unexpected scheme, or configure a ws:// websocket address believing it works for the proxy.","solutions":["Use an http:// or https:// URL for the MITM router base, e.g. 'http://localhost:20128'.","If the value was typed without a scheme, prefix it with 'http://' before submitting.","Check the settings file / env where the MITM router URL is stored and correct the scheme."],"exampleFix":"// before\nnormalizeMitmRouterBaseUrlInput(\"ftp://localhost:20128\")\n// after\nnormalizeMitmRouterBaseUrlInput(\"http://localhost:20128\")","handlingStrategy":"validation","validationCode":"function isValidHttpUrl(s) {\n  try {\n    const u = new URL(s);\n    return u.protocol === \"http:\" || u.protocol === \"https:\";\n  } catch { return false; }\n}\nif (!isValidHttpUrl(input)) input = \"http://\" + input;","typeGuard":"const isHttpUrl = (v) => {\n  try { const u = new URL(v); return [\"http:\",\"https:\"].includes(u.protocol); }\n  catch { return false; }\n};","tryCatchPattern":"try {\n  await configureMitm(routerUrl);\n} catch (e) {\n  if (e.message.includes(\"must use http or https\")) {\n    console.error(\"Fix the scheme, e.g. http://host:port\");\n  } else throw e;\n}","preventionTips":["Always include an explicit http:// or https:// scheme in router URLs","Never use ws:// or other schemes for the MITM router base","Validate config values at startup with a URL-scheme check"],"tags":["validation","url","mitm-proxy"],"backgroundTag":"invalid-url-scheme","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}