{"record":{"id":"ca065e2976f629b6","repo":"santifer/career-ops","slug":"4dayweek-untrusted-hostname-parsed-hostname","errorCode":null,"errorMessage":"4dayweek: untrusted hostname \"${parsed.hostname}\" — must be ${TRUSTED_HOST}","messagePattern":"4dayweek: untrusted hostname \"(.+?)\" — must be (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"providers/4dayweek.mjs","lineNumber":57,"sourceCode":"      }\n    } catch {\n      // Ignore malformed URLs; another provider may still claim the entry.\n    }\n  }\n  return null;\n}\n\n/** @param {string} url */\nfunction assertFourDayUrl(url) {\n  let parsed;\n  try {\n    parsed = new URL(url);\n  } catch {\n    throw new Error(`4dayweek: invalid URL: ${url}`);\n  }\n  if (parsed.protocol !== 'https:') throw new Error(`4dayweek: URL must use HTTPS: ${url}`);\n  if (parsed.hostname !== TRUSTED_HOST) {\n    throw new Error(`4dayweek: untrusted hostname \"${parsed.hostname}\" — must be ${TRUSTED_HOST}`);\n  }\n  return url;\n}\n\n/** Resolve the page cap: a positive integer `max_pages` on the entry, capped. */\nfunction resolveMaxPages(entry) {\n  const v = entry?.max_pages;\n  if (Number.isInteger(v) && v > 0) return Math.min(v, MAX_PAGES_CAP);\n  return DEFAULT_MAX_PAGES;\n}\n\n// NaN-safe: posted is epoch SECONDS → ms; anything non-finite yields undefined.\nfunction toEpochMs(seconds) {\n  return Number.isFinite(seconds) ? seconds * 1000 : undefined;\n}\n\n/**\n * Normalize a single 4 Day Week job. Exported for unit tests.","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/providers/4dayweek.mjs#L39-L75","documentation":"This error is thrown by assertFourDayUrl in providers/4dayweek.mjs when a URL passed to the 4dayweek provider parses successfully but its hostname does not exactly match the provider's single allowed TRUSTED_HOST. The provider only fetches from its own known feed host, so any other hostname is rejected as a guard against SSRF and misconfigured feed URLs. HTTPS is also enforced separately, but this specific throw fires only when the protocol check already passed and the hostname is wrong.","triggerScenarios":"Calling the provider with a feed/entry URL whose parsed hostname !== TRUSTED_HOST (e.g. an http->https-correct URL pointing at a mirror domain, a typo like '4dayweek.io' instead of the exact trusted host, or a portals.yml careers_url that points at the company site rather than the feed host).","commonSituations":"A custom portals.yml entry with a wrong careers_url; a provider config copied from another provider whose TRUSTED_HOST differs; DNS or proxy rewrites changing the host; someone testing against a local/staging mirror of the feed.","solutions":["Check the URL's hostname and correct it to the exact TRUSTED_HOST value defined at the top of providers/4dayweek.mjs.","If you intended a different host, that host is intentionally unsupported — remove the entry or point it at the official 4dayweek feed.","Verify there is no stray path/port/subdomain confusion by printing new URL(url).hostname before calling the provider."],"exampleFix":"// before\nfetch4dayweek('https://mirror.example.com/feed?page=1')\n// after\nfetch4dayweek('https://4dayweek.com/feed?page=1') // exact TRUSTED_HOST","handlingStrategy":"validation","validationCode":"const u = new URL(url);\nif (u.protocol !== 'https:' || u.hostname !== TRUSTED_HOST) {\n  throw new Error(`refusing to fetch: ${url} is not the trusted 4dayweek feed host`);\n}","typeGuard":"function isTrusted4dwUrl(url) {\n  try { const u = new URL(url); return u.protocol === 'https:' && u.hostname === TRUSTED_HOST; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  await fetch4dayweek(url);\n} catch (e) {\n  if (String(e.message).startsWith('4dayweek: untrusted hostname')) {\n    console.error(`Config error: feed URL must point at ${TRUSTED_HOST}, got: ${url}`);\n  } else throw e;\n}","preventionTips":["Keep feed URLs in one config constant rather than interpolating hostnames ad hoc.","When copying provider configs, check that TRUSTED_HOST matches the new provider.","Assert new URL(url).hostname against the expected host in config tests."],"tags":["url-validation","ssrf-protection","provider","hostname"],"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"}