santifer/career-ops · error · Error
refusing to archive restricted destination after redirect
Error message
refusing to archive restricted destination after redirect: ${postGuard.reason} What it means
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.
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.
Example fix
// before
await archiveUrl('https://acme.com/redirect?to=http://10.0.0.5/jobs/123');
// after
const res = await fetch('https://acme.com/redirect?to=http://10.0.0.5/jobs/123', { redirect: 'follow' });
if (new URL(res.url).protocol === 'https:' && !isPrivateHost(new URL(res.url).hostname)) {
await archiveUrl(res.url); // pass the resolved public URL directly
} Defensive patterns
Strategy: try-catch
Validate before calling
// Resolve redirects out-of-band and verify the destination before archiving
const res = await fetch(entryUrl, { method: 'HEAD', redirect: 'follow' });
const landed = new URL(res.url);
const safe = /^https?:$/.test(landed.protocol) && !isPrivateHostname(landed.hostname);
if (!safe) throw new Error(`entry URL redirects to non-public host: ${res.url}`); Type guard
const landedIsPublic = (page) => { const u = new URL(page.url()); return /^https?:$/.test(u.protocol) && !isPrivateHostname(u.hostname); }; Try / catch
try {
await archiveUrl(url);
} catch (err) {
if (err.message.includes('after redirect')) {
console.warn(`Open-redirect or internal destination for ${url}; flagging entry for manual review`);
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Access denied: Egress guard blocked private target IP
- Access denied: Egress guard blocked private target IP
- Access denied: Egress guard blocked private target IPv6
- Access denied: Localhost or internal domain target detected.
- agentic-jobs: untrusted hostname
AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16).
Data as JSON: /api/errors/88d131c2a38875db.
Report an issue: GitHub.
Appendix: source
Thrown at archive-posting.mjs:343
if (preGuard) {
throw new Error(`refusing to archive restricted destination: ${preGuard.reason}`);
}
const context = await browser.newContext();
await installEgressGuard(context);
const page = await context.newPage();
try {
const response = await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
const httpStatus = response?.status() ?? 0;
// Re-check where we actually landed. The route guard already inspects every
// redirect hop, so this is defence-in-depth: a first-hop-only check is the
// classic miss here, and asserting on the settled URL costs nothing.
const landedUrl = page.url();
const postGuard = rejectPrivateOrInvalid(landedUrl);
if (postGuard) {
throw new Error(`refusing to archive restricted destination after redirect: ${postGuard.reason}`);
}
// Give SPAs (Ashby, Lever, Workday) time to hydrate
await page.waitForTimeout(2000);
const pageTitle = await page.title();
const h1Text = await page.$eval('h1', el => el.innerText.trim()).catch(() => '');
const urlCompany = extractCompanyFromUrl(url);
// Parse page title first — it usually has "Role | Company" or "Company | Role".
// Fall back to h1 for the role when the page title doesn't yield one cleanly.
const detected = parsePageTitle(pageTitle);
const resolvedCompany = overrideCompany || companyHint || detected.company || urlCompany || 'unknown';
const resolvedRole = overrideRole || roleHint || detected.role || h1Text || 'job';
// Strip noisy prefixes common on Greenhouse/Lever ("Job Application for …")
const company = resolvedCompany.replace(/^job\s+application\s+for\s+/i, '').trim();
const role = resolvedRole.replace(/^job\s+application\s+for\s+/i, '').trim();View on GitHub (pinned to aac998c7ed)