{"record":{"id":"d7f8862257a47b5d","repo":"santifer/career-ops","slug":"careerviet-untrusted-hostname-parsed-hostname","errorCode":null,"errorMessage":"careerviet: untrusted hostname \"${parsed.hostname}\" — must be ${TRUSTED_HOST}","messagePattern":"careerviet: untrusted hostname \"(.+?)\" — must be (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"providers/careerviet.mjs","lineNumber":110,"sourceCode":"const UPDATED_DATE_RE = /Cập nhật(?:<!--[\\s\\S]*?-->)?\\s*:?\\s*(?:<\\/span>)?\\s*<time>([\\d/-]+)<\\/time>/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 assertCareerVietUrl(url) {\n  let parsed;\n  try {\n    parsed = new URL(url);\n  } catch {\n    throw new Error(`careerviet: invalid URL: ${url}`);\n  }\n  if (parsed.protocol !== 'https:') throw new Error(`careerviet: URL must use HTTPS: ${url}`);\n  if (parsed.hostname !== TRUSTED_HOST) {\n    throw new Error(`careerviet: 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 * @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  )\n    .replace(/\\s+/g, ' ')\n    .trim();\n}","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/providers/careerviet.mjs#L92-L128","documentation":"assertCareerVietUrl throws this when the URL is valid https but its hostname does not exactly equal the provider's single TRUSTED_HOST constant ('www.careerviet.vn'). Unlike per-tenant providers, CareerViet has exactly one legitimate origin, so the SSRF guard uses a strict equality check; any other hostname is rejected before fetching.","triggerScenarios":"A request URL reaching assertCareerVietUrl with hostname 'careerviet.vn' (missing www), a mirror/clone domain, a typo ('careerivet.vn'), or any unrelated host configured under the careerviet entry.","commonSituations":"Omitting the 'www.' prefix; redirecting the entry at a regional or spoofed mirror; pasting the company's own site instead of the CareerViet board; typos introduced during config editing.","solutions":["Set the URL host to exactly the trusted host named in the error (e.g. 'https://www.careerviet.vn').","Do not rely on redirects — the guard checks the literal hostname, so 'https://careerviet.vn' must be rewritten, not redirected.","Verify the entry is actually a CareerViet posting; unrelated boards belong under a different provider.","Check for lookalike-character typos in the hostname."],"exampleFix":"# before\ncareers_url: https://careerviet.vn/viec-lam\n# after\ncareers_url: https://www.careerviet.vn/viec-lam","handlingStrategy":"validation","validationCode":"const TRUSTED_HOST = 'www.careerviet.vn';\nfunction isTrustedCareerVietHost(u) {\n  try { return new URL(u).hostname === TRUSTED_HOST; } catch { return false; }\n}\nif (!isTrustedCareerVietHost(entry.careers_url)) throw new Error(`careerviet entry host must be ${TRUSTED_HOST}`);","typeGuard":"function isTrustedHost(hostname) { return hostname === 'www.careerviet.vn'; }","tryCatchPattern":"try {\n  await provider.fetch(entry, ctx);\n} catch (err) {\n  if (String(err.message).startsWith('careerviet: untrusted hostname')) {\n    console.warn(`Skipping entry: hostname is not ${'www.careerviet.vn'} — check portals.yml`);\n    return null;\n  }\n  throw err;\n}","preventionTips":["Use the exact trusted host including the 'www.' prefix — the guard is strict equality, not a suffix match.","Never count on redirects from careerviet.vn to www.careerviet.vn; the guard rejects pre-redirect hosts.","Validate hostnames in a startup config check against the provider's TRUSTED_HOST constant.","Watch for lookalike-character typos when editing the hostname by hand."],"tags":["url","ssrf","allowlist","security","config"],"backgroundTag":"untrusted-hostname","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"}