Skip to content

fix(crawler): keep the headers technology detection reads for local audits #871 - #923

Merged
nc9 merged 2 commits into
mainfrom
fix/871-tech-detect-header-subset
Oct 17, 2026
Merged

nc9 merged 2 commits into
mainfrom
fix/871-tech-detect-header-subset

Conversation

@nc9

@nc9 nc9 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

In a local audit, technology detection now sees every response header a signature reads. Before, the crawler stored only a fixed subset, so header-only fingerprints such as X-CDN: Imperva, X-Sucuri-ID and X-Varnish never matched.

Closes #871

What changed

  • @squirrelscan/utils constants.

    • TECH_DETECT_HEADER_NAMES: the 45 headers that a tech-detect fingerprint, or a WAF provider in the Technologies section, reads.
    • TECH_DETECT_PRESENCE_HEADERS: the 29 of those that are only tested for presence, such as request ids and Kasada/PerimeterX/DataDome tokens.
    • A 512-character cap per stored value.
    • audit-engine tests fail if either list drifts from the fingerprints or the WAF providers.
  • Crawler. ResponseHeaders.techHeaders is a new optional field. It is stored in the existing headers JSON column, so there is no migration. It holds:

    • listed headers only, each value capped;
    • "1" for a presence-only header, so tokens are never stored;
    • set-cookie as cookie names only (name= per line).

    It is refreshed when an incremental crawl reuses an unchanged page.

  • overlayTechHeaders (utils/headers). When a record has techHeaders (an object, or null meaning none were sent), it is authoritative for every listed header. A header the response stopped sending is dropped, so a stale curated value on a reused record cannot bring a removed technology back. An older record without the field reads as before.

  • CLI buildHeaderMap feeds both the local scan and the cloud tech-detect payload. It now passes the stored detection headers, plus the curated X-Powered-By, X-Generator and X-AspNet-Version, which were stored but not passed. Set-Cookie goes out as cookie names only, so session values and tokens never reach the cloud.

  • Endpoint discovery's detection map (buildTechHeadersMap) uses the same overlay. The rule-facing buildHeadersMap is unchanged, so rules see the same headers as before.

Acceptance criteria

  • Every header a type: "header" detector reads reaches local technology detection. The crawler stores them, and a coverage test checks the list against ALL_FINGERPRINTS and the waf-detect HEADER_PATTERNS.
  • A local audit of a fixture that answers X-CDN: Imperva lists Imperva. This is an end-to-end test: crawl, then site context, then detectLocalTechnologies. Sucuri is tested the same way.
  • Stored records do not grow without bound: only listed names are kept, with a 512-character cap per value. Presence-only headers store "1".

Tests and checks

  • New tests:
    • packages/audit-engine/tests/tech-detect-header-names-871.test.ts: list coverage, presence-set exactness, a crawler end-to-end test (capping, markers, cookie names, unlisted headers dropped), an incremental-reuse test (replacement, cookie removal, all headers removed) and unit tests for the overlay.
    • apps/cli/tests/audit/tech-detect-local-headers-871.test.ts: the local scan finds Imperva and Sucuri; the cloud payload has set-cookie: PHPSESSID= and x-kpsdk-ct: 1, and no cookie value or token.
  • Typecheck is clean for utils, crawler, audit-engine, waf-detect and cli.
  • Related tests pass: audit-engine endpoint-discovery, build-headers-map, cloud-tech-section, waf-tech-set-cookie and charset e2e; tech-detect; CLI streamed-payload-parity.
  • Engine golden tests pass (209).
  • oxfmt and oxlint are clean on the changed CLI files.
  • tangly --strict and check-links pass.
  • Codex reviewed in 3 rounds and ended with "no findings". Its fixes are included: token presence markers, stale curated fields on reuse, removed headers, and the endpoint-discovery map.

Docs

docs/cloud/technologies.mdx now describes:

  • which headers are kept, the 512-character cap, presence markers and cookie names;
  • that pages reused from the crawl cache stay as they were until refetched.

It also corrects "logged out or --offline: skipped". The CLI already runs the same signatures locally in that case (#407).

Skill impact

None. The squirrel skill does not describe how technologies are detected or which headers are kept.

@claude

claude Bot commented Oct 17, 2026

Copy link
Copy Markdown

Review of #923 (local technology detection headers). I read the diff only. I did not run the tests or the build.

The design holds up. Presence-only headers are stored as a marker, cookie values are never kept, values are capped at 512 characters, and the name list is guarded by tests against the fingerprints and WAF patterns. I found nothing that should block the merge.

  • (low) packages/crawler/src/fetcher.ts (extractTechHeaders) and apps/cli/src/audit/cloud.ts (setCookieNames) duplicate the cookie-name extraction. A Set-Cookie with no =, such as a malformed foo; Secure, becomes foo; Secure=, so attributes can leak into the name. Share one helper in utils and take the name only up to the first ; or =.
  • (low) extractTechHeaders truncates the joined cookie-name string to 512 characters. A site with many cookies can lose names, and the last name can be cut mid-way. A cut name could miss a fingerprint match, or match one wrongly. Cap per name or per count instead, or document the limit.
  • (low) overlayTechHeaders mutates and returns its map argument. Every current caller passes a fresh map, so this is safe today. Say so in the doc comment, or copy the map, so a later caller does not hit an aliasing bug.
  • (nit) packages/utils/src/headers.ts: overlayTechHeaders was inserted between the existing "Shared validation… rehydration" comment block and recordToHeaders, which separates that comment from the function it describes. Move the new function above that comment.
  • (nit) TECH_DETECT_PRESENCE_HEADERS is a hand-maintained list, though a test checks it. A comment pointing at the failing test would help contributors who add a fingerprint.
  • (nit) Existing pages keep techHeaders undefined until they are refetched. This is documented in the changelog and the docs, so no action is needed.

Test coverage is good: the header-name drift guards, the crawler storage and cap behaviour, the incremental-reuse refresh, and the cloud payload check that no session value or token is sent.

nc9 added 2 commits October 18, 2026 04:28
…udits #871

A local audit detects technologies from the page records the crawler
stores, and the crawler kept only a fixed set of headers, so a header-only
fingerprint (X-CDN: Imperva, X-Sucuri-ID, X-Varnish) never matched.

- utils: TECH_DETECT_HEADER_NAMES (every header a tech-detect fingerprint or
  WAF provider reads), TECH_DETECT_PRESENCE_HEADERS (those read for presence
  only) and a 512-character cap per value. audit-engine tests keep both lists
  in step with the fingerprints and WAF providers.
- crawler: stores techHeaders on each page: listed headers only, capped;
  presence-only headers (request ids, bot protection tokens) as "1";
  Set-Cookie as cookie names. Refreshed when an incremental crawl reuses an
  unchanged page.
- overlayTechHeaders: when a record carries techHeaders they speak for every
  listed header, so a header the response stopped sending cannot come back
  from a stale curated field.
- CLI buildHeaderMap (local scan and cloud payload) and endpoint discovery's
  detection map use them. Rules keep buildHeadersMap unchanged.

Closes #871

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/871-tech-detect-header-subset branch from d7e4398 to e3dcbdf Compare October 17, 2026 17:28
@nc9

nc9 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Review triage, fixed in e3dcbdf (also rebased on main after #921):

  • Cookie-name extraction is now one helper, techCookieNames in utils/headers, used by the crawler and by the CLI fallback for older records. A name ends at the first = or ;, so foo; Secure gives foo=.
  • Names are no longer cut: a name over 512 characters is dropped, and at most TECH_DETECT_MAX_COOKIE_NAMES (50) are kept, each whole. Tests cover these cases.
  • The overlayTechHeaders doc comment now says the map is changed in place and must be built for the call.
  • The function sits above the rehydration comment block again.
  • The TECH_DETECT_PRESENCE_HEADERS comment points at the test that guards it.

@claude

claude Bot commented Oct 17, 2026

Copy link
Copy Markdown

Review of #923 (local technology detection reads stored headers). I read the diff only and did not run the tests.

I found no blocking problems. Cookie values and presence-only tokens never reach storage or the cloud payload, and the tests check that.

  • (low) packages/utils/src/headers.ts overlayTechHeaders: it deletes every name in TECH_DETECT_HEADER_NAMES from the map, including server and vary, and the page's techHeaders must then supply them again. The function relies on every crawl path storing techHeaders for all names. A path that sets techHeaders to {} or a partial object would silently drop curated values. The undefined versus null distinction is also easy to break, for example if storage ever serialises null as undefined. The incremental-crawl test covers the null case, which is good. Consider a comment or test on the storage round-trip for null.
  • (low) packages/crawler/src/fetcher.ts extractTechHeaders: the cap uses slice, which counts UTF-16 units and could split a surrogate pair. This is harmless for headers.
  • (nit) techCookieNames uses names.includes for de-duplication. It is O(n²), but n is capped at 50, so it is fine. A Set would read more clearly.
  • (nit) TECH_DETECT_PRESENCE_HEADERS has to stay in sync with the fingerprints. The audit-engine test enforces this, which is a good guard.
  • (nit) apps/cli/src/audit/cloud.ts: setCookieNames re-derives names from the legacy setCookie field. The overlay then replaces them whenever techHeaders is present, so the two paths cannot disagree.

Test coverage is good: end-to-end crawl fixtures, a reused cached page, truncation, and a check that no cookie value reaches the cloud payload. The changelog and docs are updated.

@nc9

nc9 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Triage of the last review (e3dcbdf), nothing blocking:

  • null vs undefined through storage: the incremental-crawl test covers it. Its last crawl reads the page back from SQLite and asserts techHeaders is null and that x-powered-by is gone from the detection map. Every crawl path that stores techHeaders builds it with extractTechHeaders, so it is null or complete. Error pages leave it undefined and fall back to the curated fields.
  • slice on a surrogate pair: header values are ByteStrings, so in practice they are Latin-1. Leaving it.
  • includes vs a Set for at most 50 names: leaving it.

@nc9
nc9 merged commit bdde55d into main Oct 17, 2026
15 checks passed
@nc9
nc9 deleted the fix/871-tech-detect-header-subset branch October 17, 2026 17:43
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.

tech-detect in a local audit only sees a fixed header subset, so header-only fingerprints never match

1 participant