Skip to content

fix(cli): seed redirect probe and cache Vary key use the custom User-Agent header #2316 - #2361

Merged
nc9 merged 1 commit into
mainfrom
fix/2316-custom-ua-seed-probe
Nov 26, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/2316-custom-ua-seed-probe

Conversation

@longshore-nc9

@longshore-nc9 longshore-nc9 Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Closes #2316.

What changed and why

When an audit sets a custom User-Agent header (-H "user-agent: ..." or [crawler] headers) and [crawler] user_agent is also set, page requests send the header (applyBrowserHeaders keeps a header the request already has). Two places still used [crawler] user_agent:

  • Seed redirect probe. resolveAuditStart (apps/cli/src/cli/start-redirect.ts) takes a new customHeaders input and sends customUserAgent(customHeaders) || userAgent. Only the agent is read from those headers; no other custom header is passed to resolveStartRedirect. The CLI audit command passes [crawler] headers merged with -H. The MCP audit_website tool now passes [crawler] user_agent and the merged headers too (it passed no agent before, so the probe sent the fallback agent).
  • Cache Vary key. buildCacheRequestContext in packages/crawler/src/core/crawler.ts now takes the custom headers that page's request carries (customHeadersFor(url), so none off the header scope) and keys user-agent on their User-Agent when present, else config.userAgent. Both the lookup and the stored page's requestHeaders use it.

Docs: the -H paragraph in docs/configuration/crawler.mdx now names the start-URL redirect probe among the requests that use the custom agent, and says it wins over user_agent.

Tests

  • apps/cli/tests/cli/audit-seed-probe-custom-user-agent-2316.test.ts (new, e2e): the real CLI in a subprocess, [crawler] user_agent set plus a secret custom header in TOML, -H "<User-Agent|user-agent|USER-AGENT>: custom". A local server is the subprocess's HTTP proxy, 403s every other agent and redirects example.com to www.example.com. Asserts exit 0, the first request is the apex probe with the custom agent and no secret header, the base URL is www.example.com, /about was crawled, and crawl requests do carry the secret. Without the fix: exit 3 on all three casings.
  • apps/cli/tests/cli/start-redirect.test.ts (new case): resolveAuditStart hands the resolver the custom agent over userAgent in every casing, the configured agent without one, and never the other header value. Fails without the fix.
  • apps/cli/tests/mcp/audit-website-start-redirect.test.ts (new case): MCP audit_website probe sends the custom agent over [crawler] user_agent, no other custom header. Fails without the fix.
  • packages/crawler/tests/cache-vary-custom-user-agent-2316.test.ts (new): crawl with an injected cache store and fetcher; the lookup context and the saved page's requestHeaders hold the agent the request actually put on the wire (computed with the real applyBrowserHeaders), for all three casings; without a custom agent, the configured one. fetch is spied to refuse any network call. The first case fails without the fix.

Expected values come from the agent the request actually sent (recorded by the server or by applyBrowserHeaders), not from the code's own selection helper.

Commands run

  • bun run scripts/test-suites.ts --run crawler: 1188 pass, 0 fail
  • bun run scripts/test-suites.ts --run cli: 4673 pass, 14 skip, 0 fail
  • bun run scripts/test-suites.ts --check: OK
  • apps/cli: bun run format:check, bun run lint, bun run typecheck: clean
  • packages/crawler: bun run typecheck clean; oxfmt --check and oxlint on the changed files (the only lint findings in crawler.ts are pre-existing no-loop-func on untouched lines)
  • bun run docs:check: pass
  • bun scripts/changelog.ts check: OK

Not in scope, noted for review: the reachability check before the crawl and the crawl's own config.userAgent (robots and other probes without custom headers) still prefer [crawler] user_agent over a custom header (user_agent || customUserAgent(headers) in controllers/audit.ts and controllers/crawl.ts). The e2e audit succeeds regardless, since a 403 there does not stop the audit.

Docs: docs/configuration/crawler.mdx. Skill: none.

…Agent header #2316

Signed-off-by: longshore-nc9[bot] <360568931+longshore-nc9[bot]@users.noreply.github.com>
@nc9
nc9 marked this pull request as ready for review November 25, 2026 06:59
@nc9
nc9 merged commit 030f5e5 into main Nov 26, 2026
13 of 22 checks passed
@nc9
nc9 deleted the fix/2316-custom-ua-seed-probe branch November 26, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Seed redirect probe and cache Vary key should use the custom User-Agent header when one is set

1 participant