Skip to content

fix(engine): custom headers stay on the audited origin; probes follow redirects by hand #732 #820 - #957

Merged
nc9 merged 2 commits into
mainfrom
fix/2831-probe-header-scope
Oct 20, 2026
Merged

nc9 merged 2 commits into
mainfrom
fix/2831-probe-header-scope

Conversation

@nc9

@nc9 nc9 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #820, closes #732. Refs private issue #2831 (same class).

What

  • The soft-404 confirmation and the cloaking probe followed redirects natively, so a redirect to another host replayed the audit's custom headers (auth, cookies, API keys, Web Bot Auth). Both now share one helper (lib/probe-fetch.ts) over safeRedirectFetch: headers dropped on a cross-origin hop, every hop vetted by the own-site egress policy (link-local and metadata refused, LAN allowed). Same-origin unchanged. (soft-404 confirmation re-fetch can send custom request headers across a redirect to another origin #820)
  • Custom headers on asset requests went to the audited host and every subdomain. They now go to the audited origin (scheme, host, port of the start URL after redirects) plus hosts named in [crawler] header_hosts or --header-host. Completions and docs updated. An asset on another host answering 401/403 without them is reported as not checked in reliability/broken-resources and mobile/web-app-manifest, naming the host. (Custom request headers reach every subdomain of the audited host: limit them to the audited origin #732)

Why: a subdomain is not always run by the site's owner (user content, SaaS CNAMEs, dangling CNAMEs), and these headers usually carry credentials.

Tests: probe-redirect-headers.test.ts (two loopback origins: cross-origin hop gets nothing, same-origin keeps, metadata refused, LAN soft-404 still confirms), header-scope-732.test.ts (scope rules, resource and script pools), rule tests for the 401 verdict.

Notes

  • New optional egressPinnedByTransport on runStreamingRules for the hosted caller.
  • Not in this PR: the cloud "Custom request headers" setting does not yet let a user name hosts, so cloud audits send them to the audited origin only (private follow-up).
  • Out of scope, pre-existing: sitemap and RSL fetches compare host without scheme.

skills: no change

…the audited origin #2831

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 20, 2026

Copy link
Copy Markdown

Reviewed the diff and the safeRedirectFetch / headersForRedirect code it builds on. The fix looks correct and I found nothing that should block the merge.

Findings

  • (low) probe-fetch.ts: probeFetch throws EgressRefusedError for a non-http(s) start URL, while safeRedirectFetch throws TypeError for the same case. Both probes catch everything, so this has no effect today. The extra check also duplicates the one inside safeRedirectFetch. Either drop it or note why it is there.
  • (low) adapter.ts probeEgress: resolve: memoizeResolveHost(resolveHostAddresses) creates a new memo cache on every call. The call is made once per probe set, so the cache is never shared with the asset phase's own-site pool. If the asset phase already builds one, reuse it so each host is resolved once per audit.
  • (low) adapter.ts (the runRulesOnStorage call sites): these use probeEgress(...) with pin defaulting to true. runStreamingRules gains egressPinnedByTransport, but the hosted caller has to pass it in the gitlink bump, as the PR notes. If the hosted caller misses that bump, its probes pin their own hops and may conflict with the egress proxy. Keep the follow-up on a checklist.
  • (nit) probe-redirect-headers.test.ts: reset() is called inside each test. A beforeEach(reset) would be cleaner. The typeof egress === "function" ? egress() : egress indirection exists only because policy is assigned in beforeAll. A comment would help.
  • (nit) probe-redirect-headers.test.ts: /meta is asserted only through rejects.toThrow() and defaultStatus === 0. Assert on EgressRefusedError, or check that the request to 169.254.169.254 was never attempted. As written, a plain connection failure to that address would also pass.

Checked

  • Cross-origin hops keep only the allowlisted capability headers (accept*, user-agent, and similar). Same-origin hops keep every header. This matches the stated intent.
  • The 10-hop redirect cap and the scheme check apply to both probes through safeRedirectFetch.
  • Undecoded bodies are preserved on every hop through fetchUndecoded (#2717).
  • The tests use real loopback servers and cover the cross-origin, same-origin and metadata cases for the helper and for both probes.

I did not run the test suite.

@nc9 nc9 changed the title fix(engine): probes follow redirects by hand, custom headers stay on the audited origin #2831 fix(engine): custom headers stay on the audited origin; probes follow redirects by hand #732 #820 Oct 20, 2026
@claude

claude Bot commented Oct 20, 2026

Copy link
Copy Markdown

Reviewed the diff and read safe-fetch.ts for the redirect handling. I did not run the tests.

The change looks sound. createHeaderScope limits the custom headers to the audited origin plus named hosts. The soft-404 and cloaking probes now follow redirects by hand through safeRedirectFetch, which drops the secret headers on a cross-origin hop via headersForRedirect. They also apply an egress policy that refuses link-local and metadata addresses. The tests use real loopback servers.

  • (low) packages/audit-engine/src/lib/header-scope.ts: a header_hosts entry matches the host on any port and scheme, so http://assets.example.com also gets the secrets. The docs say this, but the header_hosts schema or docs could warn that a named host receives credentials over plain HTTP too.
  • (low) packages/audit-engine/src/adapter.ts: the withheld() helper also treats a 401/403 from a host the headers were withheld from as "not checked". A genuinely broken asset on that host will be reported as not checked. That seems the intended tradeoff, but the rule message should make it clear.
  • (nit) resource-checker.ts: the new customHeadersFor(...) lines are long. They are worth wrapping to match the Prettier style.
  • (nit) header-scope-732.test.ts: the bare { ... } block around a single test is unnecessary.
  • (nit) Tests: there is no test for the --header-host comma-split or for the mergeOptionsToConfig merge into header_hosts. Adding one would be cheap.

No blocking issues found.

@nc9

nc9 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Negative control done: with the probe fetch reverted to native redirect: follow, probe-redirect-headers.test.ts fails 6 of 10 (cross-origin header leak for the helper, cloaking probe and soft-404 confirmation, plus both metadata-redirect cases); on this branch all 10 pass.

@nc9
nc9 merged commit 317e609 into main Oct 20, 2026
15 checks passed
@nc9
nc9 deleted the fix/2831-probe-header-scope branch October 20, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant