{"record":{"id":"b042478848b2da55","repo":"santifer/career-ops","slug":"h1b-api-base-must-not-embed-credentials","errorCode":null,"errorMessage":"H1B_API_BASE must not embed credentials.","messagePattern":"H1B_API_BASE must not embed credentials\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/lib/api.mjs","lineNumber":55,"sourceCode":"  // (an unset shell variable, an empty .env line, a CI secret that did not\n  // populate), and silently falling back would send someone's shortlist and\n  // their token to a host they believed they had replaced.\n  if (raw === undefined) return DEFAULT_BASE;\n  const trimmed = String(raw).trim();\n  if (!trimmed) {\n    throw new Error('H1B_API_BASE is set but empty. Unset it to use the default endpoint.');\n  }\n\n  let parsed;\n  try {\n    parsed = new URL(trimmed);\n  } catch {\n    throw new Error(`H1B_API_BASE is not a valid URL: ${trimmed}`);\n  }\n  if (parsed.username || parsed.password) {\n    // 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.","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/h1b-sponsor/lib/api.mjs#L37-L73","documentation":"resolveBase throws this when H1B_API_BASE embeds userinfo credentials (user:password@host). Undici refuses a credentialed Request anyway, and the base URL is echoed to stdout through the source field, so credentials would leak into logs.","triggerScenarios":"H1B_API_BASE set to something like https://user:token@my-worker.example.com — e.g. pasting a URL that includes basic-auth credentials copied from a browser or another tool.","commonSituations":"Copy-pasting an authenticated URL from curl history or a shared doc; configuring a Cloudflare-protected worker with inline basic auth instead of a token header.","solutions":["Remove the user:password@ portion from the URL.","Pass the token out-of-band (e.g. a dedicated token env var consumed by the worker) rather than in the URL.","Rotate the credential if it was already printed to logs/stdout."],"exampleFix":"// before\nH1B_API_BASE=https://user:s3cret@my-worker.example.com\n// after\nH1B_API_BASE=https://my-worker.example.com","handlingStrategy":"validation","validationCode":"const u = new URL(process.env.H1B_API_BASE);\nif (u.username || u.password) throw new Error('H1B_API_BASE must not contain credentials');","typeGuard":"function isCredentialFreeUrl(s) {\n  try { const u = new URL(s); return !u.username && !u.password; } catch { return false; }\n}","tryCatchPattern":"try {\n  await lookup(name);\n} catch (e) {\n  if (e.message.includes('must not embed credentials')) {\n    console.error('Move the credential out of the URL and rotate it — it may already be in logs.');\n  }\n}","preventionTips":["Never paste authenticated URLs (user:pass@host) into config.","Use header/token-based auth for the worker, not URL userinfo.","Rotate any credential that has appeared in stdout/logs."],"tags":["env","url","security"],"backgroundTag":"invalid-config-value","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"}