{"record":{"id":"9928ffc8581a53ce","repo":"santifer/career-ops","slug":"refusing-to-archive-restricted-destination-preg","errorCode":null,"errorMessage":"refusing to archive restricted destination: ${preGuard.reason}","messagePattern":"refusing to archive restricted destination: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"archive-posting.mjs","lineNumber":326,"sourceCode":"\n    try {\n      await validateUrlSecurity(requestUrl);\n      return route.continue();\n    } catch (err) {\n      console.warn(`   Blocked request to restricted destination (DNS): ${requestUrl} - ${err.message}`);\n      return route.abort('blockedbyclient');\n    }\n  });\n}\n\nexport async function archiveUrl(browser, url, { company: companyHint, role: roleHint } = {}) {\n  console.log(`\\n🔗  ${url}`);\n\n  // Refuse before launching any navigation, so an obviously-internal target\n  // never reaches Playwright at all.\n  const preGuard = rejectPrivateOrInvalid(url);\n  if (preGuard) {\n    throw new Error(`refusing to archive restricted destination: ${preGuard.reason}`);\n  }\n\n  const context = await browser.newContext();\n  await installEgressGuard(context);\n  const page = await context.newPage();\n\n  try {\n    const response = await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });\n    const httpStatus = response?.status() ?? 0;\n\n    // Re-check where we actually landed. The route guard already inspects every\n    // redirect hop, so this is defence-in-depth: a first-hop-only check is the\n    // classic miss here, and asserting on the settled URL costs nothing.\n    const landedUrl = page.url();\n    const postGuard = rejectPrivateOrInvalid(landedUrl);\n    if (postGuard) {\n      throw new Error(`refusing to archive restricted destination after redirect: ${postGuard.reason}`);\n    }","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/archive-posting.mjs#L308-L344","documentation":"archiveUrl performs a pre-navigation safety check with rejectPrivateOrInvalid(url) before launching Playwright, refusing destinations that are private/internal or otherwise invalid (localhost, private IP ranges, non-http schemes, malformed URLs). This is an SSRF-style guard: an obviously-internal target must never reach the browser at all. The thrown message embeds the guard's specific reason.","triggerScenarios":"Passing http://localhost:3000/jobs/123, a private-network address (192.168.x.x, 10.x.x.x, 127.0.0.1), a file:// or other non-public-scheme URL, an empty or malformed string, or a URL pasted from an internal tool into archiveUrl.","commonSituations":"Testing the archiver against a local dev server or a staging host on an internal network; a pipeline entry containing a truncated or typo'd URL; accidentally archiving an admin/intranet posting URL; copy-pasting a URL from a local ATS instance.","solutions":["Use the public, internet-reachable posting URL (e.g. the https:// boards.greenhouse.io/... or jobs.lever.co/... link) instead of a localhost or internal address.","Inspect preGuard.reason (print the error) to see which rule fired — invalid URL vs private host — and fix the input accordingly.","Validate/normalize the URL before calling: new URL(raw), require https: protocol, and confirm the host resolves publicly.","If you legitimately need to archive an internal page, this function is not the tool — use Playwright directly outside this guarded path."],"exampleFix":"// before\nawait archiveUrl('http://localhost:8080/jobs/senior-eng');\n// after\nconst url = new URL('https://jobs.lever.co/acme/senior-eng');\nif (url.protocol === 'https:' && !/^localhost$|^(10|127)\\.|192\\.168\\./.test(url.hostname)) {\n  await archiveUrl(url.href);\n}","handlingStrategy":"validation","validationCode":"function isPublicHttpUrl(raw) {\n  try {\n    const u = new URL(raw);\n    if (u.protocol !== 'https:' && u.protocol !== 'http:') return false;\n    if (/^(localhost|127\\.|10\\.|192\\.168\\.|172\\.(1[6-9]|2\\d|3[01])\\.)/.test(u.hostname)) return false;\n    return true;\n  } catch { return false; }\n}\nif (!isPublicHttpUrl(url)) throw new Error(`not a public URL: ${url}`);","typeGuard":"const isSafeDestination = (raw) => { try { const u = new URL(raw); return /^https?:$/.test(u.protocol) && !isPrivateHostname(u.hostname); } catch { return false; } };","tryCatchPattern":"try {\n  await archiveUrl(url);\n} catch (err) {\n  if (err.message.startsWith('refusing to archive restricted destination:')) {\n    console.error(`Skipping ${url}: ${err.message.split(': ').pop()} (not a public posting URL?)`);\n    // mark the pipeline entry as needs-manual-review instead of retrying\n  } else throw err;\n}","preventionTips":["Only archive public https:// posting URLs (Greenhouse/Lever/Ashby/Workday boards).","Never test the archiver against localhost or staging — use the production board URL.","Parse and normalize URLs before calling; reject non-http(s) schemes early.","Read the embedded reason in the message — it names the exact guard rule that fired."],"tags":["security","ssrf","url-validation"],"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"}