{"record":{"id":"88d131c2a38875db","repo":"santifer/career-ops","slug":"refusing-to-archive-restricted-destination-after-r","errorCode":null,"errorMessage":"refusing to archive restricted destination after redirect: ${postGuard.reason}","messagePattern":"refusing to archive restricted destination after redirect: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"archive-posting.mjs","lineNumber":343,"sourceCode":"  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    }\n\n    // Give SPAs (Ashby, Lever, Workday) time to hydrate\n    await page.waitForTimeout(2000);\n\n    const pageTitle = await page.title();\n    const h1Text = await page.$eval('h1', el => el.innerText.trim()).catch(() => '');\n    const urlCompany = extractCompanyFromUrl(url);\n\n    // Parse page title first — it usually has \"Role | Company\" or \"Company | Role\".\n    // Fall back to h1 for the role when the page title doesn't yield one cleanly.\n    const detected = parsePageTitle(pageTitle);\n    const resolvedCompany = overrideCompany || companyHint || detected.company || urlCompany || 'unknown';\n    const resolvedRole = overrideRole || roleHint || detected.role || h1Text || 'job';\n\n    // Strip noisy prefixes common on Greenhouse/Lever (\"Job Application for …\")\n    const company = resolvedCompany.replace(/^job\\s+application\\s+for\\s+/i, '').trim();\n    const role = resolvedRole.replace(/^job\\s+application\\s+for\\s+/i, '').trim();","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/archive-posting.mjs#L325-L361","documentation":"After navigation, archiveUrl re-checks the final landed URL with rejectPrivateOrInvalid as defence-in-depth against open-redirects: a public-looking entry URL can redirect (or be redirected by an SPA/ATS) to a private or invalid destination. If the settled URL fails the guard, it throws with this message. The per-hop route guard plus this settled-URL assertion ensure no internal page is ever captured.","triggerScenarios":"The posting URL redirects to an internal host (corporate SSO on a private network, an intranet mirror), an open redirect on the ATS bounces to localhost/10.x.x.x, or a maliciously crafted job link uses the company's domain to redirect to an internal address.","commonSituations":"Archiving a posting behind an internal-only ATS mirror where the public URL 302s inward; a short-link (bit.ly-style) that resolves to a private host; a staged role whose URL now redirects to an internal HR system; testing with a redirect chain that ends on a dev server.","solutions":["Inspect postGuard.reason to learn the landed host and why it was rejected, then obtain a direct public URL that does not redirect internally.","If the posting has moved behind a login/intranet, the public archive cannot capture it — locate the equivalent public posting URL or skip the job.","Strip redirect wrappers: use the final public boards.* / jobs.* URL directly rather than a tracking or short-link URL.","Treat repeated hits as a data-quality signal: clean the source of the URL (portals.yml, pipeline.md) rather than bypassing the guard."],"exampleFix":"// before\nawait archiveUrl('https://acme.com/redirect?to=http://10.0.0.5/jobs/123');\n// after\nconst res = await fetch('https://acme.com/redirect?to=http://10.0.0.5/jobs/123', { redirect: 'follow' });\nif (new URL(res.url).protocol === 'https:' && !isPrivateHost(new URL(res.url).hostname)) {\n  await archiveUrl(res.url); // pass the resolved public URL directly\n}","handlingStrategy":"try-catch","validationCode":"// Resolve redirects out-of-band and verify the destination before archiving\nconst res = await fetch(entryUrl, { method: 'HEAD', redirect: 'follow' });\nconst landed = new URL(res.url);\nconst safe = /^https?:$/.test(landed.protocol) && !isPrivateHostname(landed.hostname);\nif (!safe) throw new Error(`entry URL redirects to non-public host: ${res.url}`);","typeGuard":"const landedIsPublic = (page) => { const u = new URL(page.url()); return /^https?:$/.test(u.protocol) && !isPrivateHostname(u.hostname); };","tryCatchPattern":"try {\n  await archiveUrl(url);\n} catch (err) {\n  if (err.message.includes('after redirect')) {\n    console.warn(`Open-redirect or internal destination for ${url}; flagging entry for manual review`);\n  } else throw err;\n}","preventionTips":["Prefer direct board URLs over short-links and tracking-redirect wrappers.","Pre-flight HEAD requests to resolve redirect chains before archiving.","Treat this error as a security signal, not a bug — never bypass the guard; fix the source URL.","Keep isPrivateHostname logic in sync with rejectPrivateOrInvalid so callers can pre-validate identically."],"tags":["security","ssrf","redirect"],"backgroundTag":"ssrf-redirect-blocked","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"}