{"record":{"id":"53415f1ca5a8e428","repo":"santifer/career-ops","slug":"h1b-api-base-must-not-contain-a-query-string-or-a","errorCode":null,"errorMessage":"H1B_API_BASE must not contain a query string or a fragment.","messagePattern":"H1B_API_BASE must not contain a query string or a fragment\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/lib/api.mjs","lineNumber":60,"sourceCode":"  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.\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;","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/h1b-sponsor/lib/api.mjs#L42-L78","documentation":"resolveBase throws this when H1B_API_BASE contains a query string or fragment. Because the plugin appends paths (`${base}/employers/...`), a `?` or `#` in the base swallows the appended path and the request hits the base itself — returning data about a company never asked for.","triggerScenarios":"H1B_API_BASE set to values like https://worker.example.com/?token=abc or https://worker.example.com#api — the constructed /employers/{id} path lands after '?' or '#'.","commonSituations":"Embedding an API key in the base URL's query string; copying a full page URL (with fragment) from a browser address bar instead of the bare origin.","solutions":["Strip any ?query or #fragment; use the bare origin (https://worker.example.com).","Move authentication to a header/token mechanism rather than the URL query.","If the worker needs a path prefix, set the base to that path without a trailing query."],"exampleFix":"// before\nH1B_API_BASE=https://worker.example.com?token=abc\n// after\nH1B_API_BASE=https://worker.example.com","handlingStrategy":"validation","validationCode":"const u = new URL(process.env.H1B_API_BASE);\nif (u.search || u.hash) throw new Error('H1B_API_BASE must not contain ?query or #fragment');","typeGuard":"function isBareBaseUrl(s) {\n  try { const u = new URL(s); return !u.search && !u.hash; } catch { return false; }\n}","tryCatchPattern":"try {\n  await lookup(name);\n} catch (e) {\n  if (e.message.includes('query string or a fragment')) {\n    console.error('Strip ?... and #... from H1B_API_BASE; use the bare origin.');\n  }\n}","preventionTips":["Copy base URLs from the origin only, not from a browser address bar.","Pass API keys via headers or dedicated env vars, never in the base URL query.","Sanitize configured URLs (strip search/hash) at startup."],"tags":["env","url","configuration"],"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"}