{"record":{"id":"0d5883c88037c9bd","repo":"santifer/career-ops","slug":"h1b-api-base-must-use-https-or-http-on-loopback","errorCode":null,"errorMessage":"H1B_API_BASE must use https, or http on loopback: ${trimmed}","messagePattern":"H1B_API_BASE must use https, or http on loopback: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/lib/api.mjs","lineNumber":71,"sourceCode":"    // Undici refuses a credentialed Request anyway, and the value reaches\n    // stdout through the source field, so this would print a password.\n    throw new Error('H1B_API_BASE must not embed credentials.');\n  }\n  if (parsed.search || parsed.hash) {\n    // Paths are appended, so a query or fragment swallows them: the request\n    // would go to the base itself and answer about a company never asked for.\n    throw new Error('H1B_API_BASE must not contain a query string or a fragment.');\n  }\n  // Plain http would put an Authorization header on the wire in the clear.\n  // Loopback is exempt so a self-hoster can develop against a local worker,\n  // but only for http. Exempting every scheme on a loopback host let\n  // ftp://localhost and ws://localhost past validation, and those die later\n  // inside fetch as a bare \"fetch failed\", which is the opaque failure this\n  // check exists to replace with a named configuration error.\n  const loopback = /^(localhost|127\\.\\d+\\.\\d+\\.\\d+|\\[::1\\]|::1)$/i.test(parsed.hostname);\n  const allowedScheme = parsed.protocol === 'https:' || (parsed.protocol === 'http:' && loopback);\n  if (!allowedScheme) {\n    throw new Error(`H1B_API_BASE must use https, or http on loopback: ${trimmed}`);\n  }\n  // Appended as `${base}/employers/...`, so a trailing slash would double up.\n  return trimmed.replace(/\\/+$/, '');\n}\nconst USER_AGENT = 'career-ops-plugin-h1b-sponsor/1.0';\nconst DEFAULT_TIMEOUT_MS = 10_000;\nconst MAX_RETRY_WAIT_MS = 10_000;\nconst MAX_REDIRECTS = 3;\n// The largest real employer profile this API serves is about 13 KB and a search\n// page is about 4 KB, so a megabyte is ~80x headroom for future growth while\n// still refusing to buffer a runaway or hostile body.\nconst MAX_READ_BYTES = 1024 * 1024;\n\nfunction buildHeaders(token) {\n  const h = { 'Accept': 'application/json', 'User-Agent': USER_AGENT };\n  if (typeof token === 'string' && token.trim()) {\n    h['Authorization'] = `Bearer ${token.trim()}`;\n  }","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/h1b-sponsor/lib/api.mjs#L53-L89","documentation":"resolveBase throws this when H1B_API_BASE uses a scheme other than https, except plain http on a loopback host (localhost/127.x/[::1]/::1). Plain http would put the Authorization header on the wire in the clear; non-HTTP schemes (ftp://, ws://) die later inside fetch as an opaque 'fetch failed', which this check replaces with a named error.","triggerScenarios":"H1B_API_BASE set to http://production-host.example.com (non-loopback http), or ftp://localhost / ws://localhost (exempted-by-accident schemes now rejected), or any non-https remote URL.","commonSituations":"Self-hosting a worker behind plain HTTP on a public host during testing; using the http:// loopback shortcut off localhost (e.g. http://192.168.1.5:8787 on a LAN address); leaving a development URL pointed at a non-HTTP protocol.","solutions":["Serve the worker over https (e.g. put it behind a TLS reverse proxy or Cloudflare) and update the variable.","For local development, use http://localhost:<port> or http://127.0.0.1:<port>, which are exempted.","If testing on a LAN host, use an https tunnel (e.g. a TLS-terminating proxy) instead of plain http."],"exampleFix":"// before\nH1B_API_BASE=http://192.168.1.5:8787\n// after (local dev)\nH1B_API_BASE=http://localhost:8787\n// or for a shared host\nH1B_API_BASE=https://h1b-worker.example.com","handlingStrategy":"validation","validationCode":"const u = new URL(process.env.H1B_API_BASE);\nconst loopback = /^(localhost|127\\.\\d+\\.\\d+\\.\\d+|\\[::1\\]|::1)$/i.test(u.hostname);\nif (!(u.protocol === 'https:' || (u.protocol === 'http:' && loopback))) {\n  throw new Error('H1B_API_BASE must be https, or http on loopback only');\n}","typeGuard":"function isAllowedBase(s) {\n  try {\n    const u = new URL(s);\n    const loopback = /^(localhost|127\\.\\d+\\.\\d+\\.\\d+|\\[::1\\]|::1)$/i.test(u.hostname);\n    return u.protocol === 'https:' || (u.protocol === 'http:' && loopback);\n  } catch { return false; }\n}","tryCatchPattern":"try {\n  await lookup(name);\n} catch (e) {\n  if (e.message.includes('must use https, or http on loopback')) {\n    console.error('Serve the worker over TLS, or use http://localhost:<port> for local dev.');\n  }\n}","preventionTips":["Terminate TLS in front of any self-hosted worker (reverse proxy or platform TLS).","Use http://localhost or http://127.0.0.1 for local development, never LAN IPs over http.","Audit env vars for non-https URLs before deploying."],"tags":["env","url","security","tls"],"backgroundTag":"invalid-url-format","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}