Skip to content

fix(crawler,engine,cli): a custom header that differs only in case replaces the built-in one - #1130

Closed
nc9 wants to merge 3 commits into
mainfrom
fix/3346-header-case
Closed

nc9 wants to merge 3 commits into
mainfrom
fix/3346-header-case

Conversation

@nc9

@nc9 nc9 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Every crawl request built its headers by spreading records, e.g. { "User-Agent": ua, Accept, ...customHeaders }. When a custom header's name differed from a built-in one only in case (-H "user-agent: x", accept in [crawler] headers), the record held both keys, and new Headers(record) appended them: the request sent a combined value such as squirrel/..., x.

Changes

  • New helper: mergeHeaderRecords (@squirrelscan/utils/headers) merges records case-insensitively; a later record wins and keeps its spelling.
  • Where it is used:
    • the page fetch (standard path and document fetcher, conditional headers still last);
    • robots.txt, sitemaps, llms.txt, markdown, well-known, RSL and agent access;
    • the asset checks (resource checker, script fetcher), the cloaking probe and the soft-404 re-fetch.
  • Probes that keep their own value on purpose:
    • agent access keeps its GPTBot/Claude-User identities;
    • the cloaking probe's Googlebot fetch keeps its agent (before, a custom User-Agent made both cloaking fetches send it, so agent-based cloaking could not show);
    • the markdown probe keeps its Accept;
    • the resource checker keeps its Range;
    • the sitemap reader keeps its Accept-Encoding.
  • CLI: -H parsing and its merge over [crawler] headers are case-insensitive.
  • Private consumers: checked. Only the cloud pace probe built headers this way, and it was fixed in squirrelscan/repo#3345.

Tests

  • utils: merge-header-records.test.ts
  • crawler: custom-header-case-3346.test.ts, a real crawl. Pages, robots, sitemap and root probes send the custom agent alone; agent access keeps its identities.
  • audit-engine: custom-header-case-3346.test.ts. Stylesheet, script and image requests send the custom agent alone; the cloaking Googlebot fetch keeps Googlebot. Both run against real servers.
  • CLI: parseHeaders and mergeOptionsToConfig across casings.

Each test fails on main.

Not in this PR

The start-URL redirect probe and the cache Vary key still use [crawler] user_agent rather than a custom agent. That is squirrelscan/repo#3351, which waits for the seed-resolution PR that rewrites that probe. The redirect probe sends no custom headers by design (#1395).

Gates

  • tsgo on utils, crawler, audit-engine and the CLI
  • CLI format:check
  • tests run by path
  • make validate
  • detect-secrets on the changed files

Independent review, then a delta review: 1 blocking and 1 medium, both fixed; the two lows (docs exceptions, CHANGELOG cloaking line) are fixed as well.

Docs: configuration/crawler.mdx (headers). Skill: no change needed (the precedence is now what the docs always said).

Fixes squirrelscan/repo#3346.

nc9 added 3 commits October 26, 2026 09:47
…places the built-in one

Every crawl request built its headers by spreading records
({ "User-Agent": ua, Accept, ...customHeaders }). A custom header whose name
differed only in case (user-agent, accept) became a second key, and
new Headers(record) appended both, sending a combined value. mergeHeaderRecords
(utils/headers) merges case-insensitively, later wins, and is used by the page
fetch (standard and document fetcher), robots, sitemaps, llms, markdown,
well-known, rsl, agent-access, the asset checks, the script fetcher and the
cloaking probe. The CLI's -H parse and its merge over [crawler] headers are
case-insensitive too.

Fixes squirrelscan/repo#3346.

Signed-off-by: Nik Cubrilovic <[email protected]>
- the cloaking probe's Googlebot fetch keeps its agent over a custom one, and
  the markdown probe its Accept (each is what the probe tests)
- Range (the size check's byte window) and the sitemap Accept-Encoding (only
  codings the reader decodes) are laid after the custom headers
- soft-404 merges a custom-header record before building Headers, so x-a and
  X-A in one TOML table go out once
- tests: CLI -H over [crawler] headers across casings, the agent-access
  identities, a real-server cloaking agent check, the Accept check that could
  not match; docs scoped to requests that carry the custom headers

Refs squirrelscan/repo#3346.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 marked this pull request as ready for review October 25, 2026 22:48
@claude

claude Bot commented Oct 25, 2026

Copy link
Copy Markdown

Review of #1130 (case-insensitive header merging).

I read the diff, including the new mergeHeaderRecords helper and its call sites. I did not run the tests.

I found nothing that should block the merge. The helper is small and correct. A later record wins, the winner keeps its spelling, and Object.fromEntries uses define semantics, so a __proto__ header name is safe. The probes that keep their own value (Googlebot cloaking fetch, markdown Accept, resource Range) are laid out correctly.

  • (low) packages/audit-engine/src/cloaking-probe.ts: withoutUserAgent is formatted on one long line (about 130 characters). Audit-engine isn't format-checked in CI, but running oxfmt on that file would match the neighbouring style.
  • (low) Several crawler files (llms.ts, markdown.ts, robots.ts) put the new import { mergeHeaderRecords } after the import type lines, which breaks the usual import grouping. This is cosmetic.
  • (nit) The withoutUserAgent filter only strips User-Agent. Other custom headers still reach the Googlebot fetch, which is probably intended. A one-line comment saying so would make that clear.
  • (nit) A test for mergeHeaderRecords with null/undefined records and a mixed-case winner would pin the documented behaviour. The PR lists merge-header-records.test.ts, so this may already be covered.

Before merging, run the secret-scan and scripts/test-suites.ts --check steps from AGENTS.md. I did not run them.

@nc9 nc9 mentioned this pull request Oct 26, 2026
@nc9 nc9 closed this in #1149 Oct 26, 2026
@nc9

nc9 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Landed in the v0.0.134 batch (#1149), main commits 644d9a5..7b22471.

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.

1 participant