{"record":{"id":"84c91586037dc99d","repo":"santifer/career-ops","slug":"senjob-untrusted-hostname-parsed-hostname","errorCode":null,"errorMessage":"senjob: untrusted hostname \"${parsed.hostname}\" — must be ${TRUSTED_HOST}","messagePattern":"senjob: untrusted hostname \"(.+?)\" — must be (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"providers/senjob.mjs","lineNumber":81,"sourceCode":"const HIDDEN_ISO_DATE_RE = /display:\\s*none;?\\s*\"?>\\s*(\\d{4}-\\d{2}-\\d{2})\\s*</i;\n\n/** @param {any} ctx @param {number} ms */\nfunction sleep(ctx, ms) {\n  if (typeof ctx?.sleep === 'function') return ctx.sleep(ms);\n  return new Promise((r) => setTimeout(r, ms));\n}\n\n/** @param {string} url */\nfunction assertSenjobUrl(url) {\n  let parsed;\n  try {\n    parsed = new URL(url);\n  } catch {\n    throw new Error(`senjob: invalid URL: ${url}`);\n  }\n  if (parsed.protocol !== 'https:') throw new Error(`senjob: URL must use HTTPS: ${url}`);\n  if (parsed.hostname !== TRUSTED_HOST) {\n    throw new Error(`senjob: untrusted hostname \"${parsed.hostname}\" — must be ${TRUSTED_HOST}`);\n  }\n  return url;\n}\n\n/**\n * Collapse a markup fragment to its visible text.\n * Comments are stripped FIRST: the anchor bodies carry `<!-- d ico postulez -->`\n * between the title and a spacer image, and a naive tag strip would leave the\n * comment body sitting inside the title.\n * @param {string} fragment\n * @returns {string}\n */\nexport function visibleText(fragment) {\n  return decodeEntities(\n    String(fragment ?? '')\n      .replace(/<!--[\\s\\S]*?-->/g, ' ')\n      .replace(/<[^>]+>/g, ' '),\n  )","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/providers/senjob.mjs#L63-L99","documentation":"This error is thrown by assertSenjobUrl in providers/senjob.mjs when a URL passes HTTPS validation but its hostname is not the single trusted host 'senjob.com'. The provider only fetches from its own list URL (https://senjob.com/offres-d-emploi.php), so any other hostname is treated as untrusted input and rejected to prevent fetching or parsing arbitrary pages. It is an SSRF/host-pinning guard, not a network failure.","triggerScenarios":"Calling senjob fetch with a portals entry or override whose URL points at a different host (e.g. www.senjob.com, senjob.net, a mirror, or a malicious link injected via config); any code path that bypasses buildListUrl and supplies its own URL to assertSenjobUrl with a foreign hostname.","commonSituations":"Configuring the senjob board with a careers_url of 'https://www.senjob.com/...' (the www prefix fails the exact-match check); typos in the host; trying to reuse the provider for a different Senegalese board like emploisenegal.com; redirect targets being followed manually.","solutions":["Use the exact host senjob.com (no www, no alternate TLD) in any URL passed to the provider","Prefer the provider's built-in buildListUrl(page) instead of hand-constructing list URLs","If a mirror host must be supported, update the TRUSTED_HOST constant or extend the hostname check in providers/senjob.mjs","Check for an accidental www. prefix or trailing proxy host in portals.yml"],"exampleFix":"// before\nconst url = 'https://www.senjob.com/offres-d-emploi.php';\n// after\nconst url = 'https://senjob.com/offres-d-emploi.php'; // exact TRUSTED_HOST","handlingStrategy":"validation","validationCode":"function isTrustedSenjobUrl(url) {\n  try {\n    const u = new URL(url);\n    return u.protocol === 'https:' && u.hostname === 'senjob.com';\n  } catch { return false; }\n}\nif (!isTrustedSenjobUrl(myUrl)) throw new Error('refusing to fetch non-senjob.com URL');","typeGuard":"const isSenjobUrl = (url) => {\n  try { return new URL(url).hostname === 'senjob.com'; } catch { return false; }\n};","tryCatchPattern":"try {\n  await senjobProvider.fetch(entry, ctx);\n} catch (e) {\n  if (String(e.message).includes('untrusted hostname')) {\n    console.error(`Config error: ${entry.name} must point at senjob.com, got: ${entry.careers_url ?? entry.api}`);\n  } else throw e;\n}","preventionTips":["Always configure senjob boards with the exact host senjob.com (no www)","Use the provider's buildListUrl(page) instead of constructing URLs by hand","Validate portals entries at startup with a hostname allowlist check","Never feed externally supplied URLs straight into the provider — derive them from config"],"tags":["url-validation","ssrf-guard","scraper","hostname-allowlist"],"backgroundTag":"invalid-url","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"}