{"record":{"id":"20033ca9153d38d4","repo":"CloakHQ/CloakBrowser","slug":"cloakbrowser-malformed-http-proxy-url-passing-t","errorCode":null,"errorMessage":"[cloakbrowser] Malformed HTTP proxy URL, passing through unchanged: invalid port","messagePattern":"\\[cloakbrowser\\] Malformed HTTP proxy URL, passing through unchanged: invalid port","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"js/src/proxy.ts","lineNumber":197,"sourceCode":" */\nexport function normalizeHttpStringUrl(urlStr: string): string {\n  const normalized = urlStr.includes(\"://\") ? urlStr : `http://${urlStr}`;\n  const schemeMatch = normalized.match(/^([a-z][a-z0-9+\\-.]*):\\/\\/(.*)$/i);\n  if (!schemeMatch) return normalized;\n  const [, scheme, rest] = schemeMatch;\n  const hostStart = rest.search(/[/?#]/);\n  const authority = hostStart === -1 ? rest : rest.slice(0, hostStart);\n  const suffix = hostStart === -1 ? \"\" : rest.slice(hostStart);\n  const atIdx = authority.lastIndexOf(\"@\");\n  if (atIdx === -1) return normalized;\n  const userinfo = authority.slice(0, atIdx);\n  const hostPart = authority.slice(atIdx + 1);\n  const bracketEnd = hostPart.lastIndexOf(\"]\");\n  const portColonIdx = hostPart.indexOf(\":\", Math.max(bracketEnd, 0));\n  if (portColonIdx !== -1) {\n    const portStr = hostPart.slice(portColonIdx + 1);\n    if (portStr && !/^\\d+$/.test(portStr)) {\n      console.warn(`[cloakbrowser] Malformed HTTP proxy URL, passing through unchanged: invalid port`);\n      return normalized;\n    }\n  }\n  const hostAndRest = hostPart + suffix;\n  const colonIdx = userinfo.indexOf(\":\");\n  const rawUserEnc = colonIdx === -1 ? userinfo : userinfo.slice(0, colonIdx);\n  const hasPassword = colonIdx !== -1;\n  const rawPassEnc = hasPassword ? userinfo.slice(colonIdx + 1) : \"\";\n  try {\n    const encUser = rawUserEnc ? encodeURIComponent(lenientDecodeURIComponent(rawUserEnc)) : \"\";\n    const encPass = hasPassword\n      ? (rawPassEnc ? encodeURIComponent(lenientDecodeURIComponent(rawPassEnc)) : \"\")\n      : null;\n    let userinfoPart: string;\n    if (encPass !== null) {\n      userinfoPart = `${encUser}:${encPass}@`;\n    } else if (encUser) {\n      userinfoPart = `${encUser}@`;","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/CloakHQ/CloakBrowser/blob/d6bad5de261bedf025280ace1d14e800aee13923/js/src/proxy.ts#L179-L215","documentation":"The HTTP/HTTPS proxy URL normalizer detected a non-numeric port in the authority and cannot safely rewrite the URL. It logs this warning and returns the (partially normalized) URL unchanged instead of corrupting it.","triggerScenarios":"Passing proxy: 'http://host:8080abc' or 'http://host:port/path' where the segment after the last colon (respecting IPv6 brackets) fails /^\\d+$/, via resolveProxyConfig or resolveProxy.","commonSituations":"Env-var proxies (HTTP_PROXY) with typos, URLs pasted with trailing slashes in the wrong place, string concatenation bugs appending text after the port, IPv6 hosts without brackets.","solutions":["Correct the URL to a numeric port: http://host:8080.","Bracket IPv6 hosts: http://[::1]:8080.","Trim whitespace and remove path/query suffixes from the proxy value; check how the env var or config was assembled.","Test the URL with new URL(proxy) before passing it to catch structural mistakes early."],"exampleFix":"// before\nconst proxy = 'http://proxy.example.com:80x/';\n\n// after\nconst proxy = 'http://proxy.example.com:8080';","handlingStrategy":"validation","validationCode":"function isValidHttpProxy(u: string): boolean {\n  try {\n    const p = new URL(u);\n    if (!/^https?:$/.test(p.protocol)) return false;\n    return p.port === '' || /^\\d+$/.test(p.port);\n  } catch { return false; }\n}\nif (!isValidHttpProxy(proxy)) throw new Error(`bad HTTP proxy URL: ${proxy}`);","typeGuard":"const isWellFormedHttpProxy = (u: string): boolean =>\n  /^https?:\\/\\/\\S+@?(\\[[^\\]]+\\]|[^:\\s\\/]+):\\d+\\/?$/.test(u.trim());","tryCatchPattern":null,"preventionTips":["Trim and validate HTTP_PROXY/HTTPS_PROXY env values in a startup preflight.","Bracket IPv6 hosts; never append paths to proxy URLs."],"tags":["proxy","http","url-parsing"],"backgroundTag":"malformed-proxy-url","analyzedSha":"d6bad5de261bedf025280ace1d14e800aee13923","analyzedAt":"2026-08-28T14:13:12.918Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}