santifer/career-ops · error · Error

H1B_API_BASE must not embed credentials.

Error message

H1B_API_BASE must not embed credentials.

What it means

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.

Solutions

  1. Remove the user:password@ portion from the URL.
  2. Pass the token out-of-band (e.g. a dedicated token env var consumed by the worker) rather than in the URL.
  3. Rotate the credential if it was already printed to logs/stdout.

Example fix

// before
H1B_API_BASE=https://user:s3cret@my-worker.example.com
// after
H1B_API_BASE=https://my-worker.example.com
Defensive patterns

Strategy: validation

Validate before calling

const u = new URL(process.env.H1B_API_BASE);
if (u.username || u.password) throw new Error('H1B_API_BASE must not contain credentials');

Type guard

function isCredentialFreeUrl(s) {
  try { const u = new URL(s); return !u.username && !u.password; } catch { return false; }
}

Try / catch

try {
  await lookup(name);
} catch (e) {
  if (e.message.includes('must not embed credentials')) {
    console.error('Move the credential out of the URL and rotate it — it may already be in logs.');
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16). Data as JSON: /api/errors/b042478848b2da55. Report an issue: GitHub.

Appendix: source

Thrown at plugins/h1b-sponsor/lib/api.mjs:55

  // (an unset shell variable, an empty .env line, a CI secret that did not
  // populate), and silently falling back would send someone's shortlist and
  // their token to a host they believed they had replaced.
  if (raw === undefined) return DEFAULT_BASE;
  const trimmed = String(raw).trim();
  if (!trimmed) {
    throw new Error('H1B_API_BASE is set but empty. Unset it to use the default endpoint.');
  }

  let parsed;
  try {
    parsed = new URL(trimmed);
  } catch {
    throw new Error(`H1B_API_BASE is not a valid URL: ${trimmed}`);
  }
  if (parsed.username || parsed.password) {
    // Undici refuses a credentialed Request anyway, and the value reaches
    // stdout through the source field, so this would print a password.
    throw new Error('H1B_API_BASE must not embed credentials.');
  }
  if (parsed.search || parsed.hash) {
    // Paths are appended, so a query or fragment swallows them: the request
    // would go to the base itself and answer about a company never asked for.
    throw new Error('H1B_API_BASE must not contain a query string or a fragment.');
  }
  // Plain http would put an Authorization header on the wire in the clear.
  // Loopback is exempt so a self-hoster can develop against a local worker,
  // but only for http. Exempting every scheme on a loopback host let
  // ftp://localhost and ws://localhost past validation, and those die later
  // inside fetch as a bare "fetch failed", which is the opaque failure this
  // check exists to replace with a named configuration error.
  const loopback = /^(localhost|127\.\d+\.\d+\.\d+|\[::1\]|::1)$/i.test(parsed.hostname);
  const allowedScheme = parsed.protocol === 'https:' || (parsed.protocol === 'http:' && loopback);
  if (!allowedScheme) {
    throw new Error(`H1B_API_BASE must use https, or http on loopback: ${trimmed}`);
  }
  // Appended as `${base}/employers/...`, so a trailing slash would double up.

View on GitHub (pinned to aac998c7ed)