{"record":{"id":"4138ddbc8a79d767","repo":"santifer/career-ops","slug":"jobbankca-invalid-url-url","errorCode":null,"errorMessage":"jobbankca: invalid URL: ${url}","messagePattern":"jobbankca: invalid URL: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"providers/jobbankca.mjs","lineNumber":98,"sourceCode":"  const keywords = Array.isArray(cfg.keywords)\n    ? cfg.keywords.filter((k) => typeof k === 'string' && k.trim()).map((k) => k.trim())\n    : [];\n  return { keywords };\n}\n\n/** @param {string} keyword @param {number} page */\nexport function buildFeedUrl(keyword, page) {\n  const params = new URLSearchParams({ searchstring: keyword, locationstring: '', page: String(page) });\n  return `${FEED_URL}?${params.toString()}`;\n}\n\n/** @param {string} url */\nexport function assertJobBankUrl(url) {\n  let parsed;\n  try {\n    parsed = new URL(url);\n  } catch {\n    throw new Error(`jobbankca: invalid URL: ${url}`);\n  }\n  if (parsed.protocol !== 'https:') throw new Error(`jobbankca: URL must use HTTPS: ${url}`);\n  if (parsed.hostname !== TRUSTED_HOST) {\n    throw new Error(`jobbankca: untrusted hostname \"${parsed.hostname}\" — must be ${TRUSTED_HOST}`);\n  }\n  return url;\n}\n\n// Resolve an Atom element's inner text: unwrap CDATA, else decode entities.\nfunction extractText(inner) {\n  const cdata = inner.match(/^\\s*<!\\[CDATA\\[([\\s\\S]*?)\\]\\]>\\s*$/);\n  if (cdata) return cdata[1].trim();\n  return decodeEntities(inner).trim();\n}\n\nfunction tagText(block, tag) {\n  const m = block.match(new RegExp(`<${tag}\\\\b[^>]*>([\\\\s\\\\S]*?)</${tag}>`, 'i'));\n  return m ? extractText(m[1]) : '';","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/providers/jobbankca.mjs#L80-L116","documentation":"assertJobBankUrl validates any URL used by the Job Bank Canada provider before it is fetched. It throws 'invalid URL' when the string cannot be parsed by the WHATWG URL constructor (new URL(url) throws) — meaning the value is not a well-formed absolute URL. This is the first gate before the HTTPS and hostname checks, guarding the provider against malformed or attacker-controlled configuration (SSRF defense).","triggerScenarios":"Calling assertJobBankUrl(url) — directly or via the jobbankca provider fetch path — with a value like '', 'jobbank.gc.ca/jobsearch', 'https://' , a URL with invalid characters, or a relative path, so new URL(url) throws a TypeError.","commonSituations":"A typo'd or missing careers_url/api field in the job_boards entry of portals.yml; an env-var placeholder ('${API_URL}') left unsubstituted; YAML folding that mangles the URL; passing a path instead of a full absolute URL.","solutions":["Print the exact url value passed in and fix the job_boards entry in portals.yml so it is a full absolute URL starting with https://","Verify no YAML/env interpolation left a literal placeholder like ${url} in the config","Validate the URL manually in Node: new URL('...') in a REPL and fix until it parses","If constructing URLs programmatically, use encodeURIComponent on query components and build from the known-good FEED_URL base"],"exampleFix":"// before\napi: jobbank.gc.ca/jobsearch/feed/jobSearchRSSfeed\n// after\napi: https://www.jobbank.gc.ca/jobsearch/feed/jobSearchRSSfeed","handlingStrategy":"validation","validationCode":"function isValidJobBankUrl(url) {\n  try {\n    return new URL(url).protocol === 'https:' && new URL(url).hostname === 'www.jobbank.gc.ca';\n  } catch {\n    return false;\n  }\n}","typeGuard":"function isHttpUrl(v) {\n  return typeof v === 'string' && v.length > 0 && URL.canParse(v);\n}","tryCatchPattern":"try {\n  assertJobBankUrl(cfg.api);\n} catch (e) {\n  if (/invalid URL/.test(e.message)) {\n    console.error(`Bad config URL for jobbankca: ${JSON.stringify(cfg.api)} — must be absolute https://`);\n    return [];\n  }\n  throw e;\n}","preventionTips":["Always store full absolute https:// URLs in portals.yml entries","Run node doctor.mjs / verify-pipeline.mjs before scans to catch config problems","Avoid hand-templating URLs from env vars without validating the result","Use URL.canParse() (Node 19.9+) for cheap pre-checks"],"tags":["url-validation","ssrf-protection","config","nodejs"],"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"}