Skip to content

test(engine): metadata-hop tests prove the egress refusal; the User-Agent redirect decision is written down - #1126

Closed
nc9 wants to merge 2 commits into
mainfrom
fix/3332-ua-and-metadata-tests
Closed

nc9 wants to merge 2 commits into
mainfrom
fix/3332-ua-and-metadata-tests

Conversation

@nc9

@nc9 nc9 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Public half of squirrelscan/repo#3332, follow-ups to the #957 redirect header work. The private half is the cloud pace probe.

  • Metadata-hop tests prove the egress refusal (packages/audit-engine/tests/probe-redirect-headers.test.ts). Covers probeFetch, the cloaking probe and the soft-404 confirmation.
    • A global fetch spy shows the metadata hop is never sent, while the redirect pointing to it is.
    • probeFetch rejects with EgressRefusedError.
    • A control redirect to a public address off the site is followed under the same policy. So a metadata case can't pass for another reason, such as a deadline or a mock miss.
    • The spy fails closed on any unexpected host.
  • User-Agent across origins, decided and written down (packages/utils/src/headers.ts). A User-Agent set through the custom headers survives a cross-origin redirect hop: it names the client, it is not a credential, and dropping it would send the hop agentless.
    • Comment, plus packages/utils/tests/redirect-headers-user-agent.test.ts.
    • docs/configuration/crawler.mdx now lists the generic client headers that survive a cross-origin hop.

No behaviour change, so no CHANGELOG entry. Skill: no change.

Gates:

  • tsgo on utils and audit-engine;
  • the two test files by path;
  • scripts/test-suites.ts --check;
  • docs make validate.

An independent review found no blocking issues. Its lows are fixed: docs wording, the spy failing closed, and the soft-404 verdict assert.

@nc9
nc9 marked this pull request as ready for review October 24, 2026 22:25
@claude

claude Bot commented Oct 24, 2026

Copy link
Copy Markdown

Reviewed the diff. This is a tests, docs and comment change with no behaviour change, and I found nothing that blocks it.

  • The control cases (public redirect followed, metadata hop never sent) mean the refusal assertions can't pass for an unrelated reason.
  • The spy throws on any unexpected host, and afterEach restores fetch.
  • The docs list matches the allowlist in headers.ts.

(nit) probe-redirect-headers.test.ts, soft-404 test: sent.length = 0 before the second run is redundant with the per-test reset in beforeEach. It's only there to separate the two halves of the test, so a short comment or a split into two tests would make that clearer.

(nit) 93.184.215.14 is hardcoded as the public control address. Add a one-line comment saying it is never contacted, because the spy answers for it. That would stop a later reader from worrying about it.

nc9 added 2 commits October 26, 2026 20:14
…gent redirect decision is written down

- probe-redirect-headers: a global fetch spy shows the metadata hop is never
  sent and the redirect to it was; probeFetch rejects with EgressRefusedError;
  a control redirect to a public address off the site IS followed, so the
  metadata case cannot pass for another reason (a deadline, a mock miss)
- headersForRedirect keeps a User-Agent set through custom headers on a
  cross-origin hop, on purpose (it names the client, not a credential); comment
  plus test; docs say so

Refs squirrelscan/repo#3332.

Signed-off-by: Nik Cubrilovic <[email protected]>
…checks its verdict; docs name every kept header

Refs squirrelscan/repo#3332.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/3332-ua-and-metadata-tests branch from 12793c9 to 64b96ed Compare October 26, 2026 09:14
@claude

claude Bot commented Oct 26, 2026

Copy link
Copy Markdown

Reviewed the diff. I found no blocking issues. I read the code only and didn't run the tests.

  • (nit) packages/audit-engine/tests/probe-redirect-headers.test.ts: the soft-404 test calls reset() and then sent.length = 0. beforeEach already clears sent per test, but reset() doesn't, so the second line is needed for the second half of that test. A short comment would say why, or you could split the metadata case and the control into two tests.
  • (nit) packages/utils/tests/redirect-headers-user-agent.test.ts: the fixtures use site.test and other.test. headersForRedirect only compares origins, so this is fine today. AGENTS.md prefers example.com hosts, and .test is treated as non-public elsewhere, so it could break if that function ever starts classifying hosts.
  • (nit) The docs sentence "Never put a secret in one of those" is good. You could also name User-Agent as the one that custom headers can set, since the others are browser defaults.

The behaviour is unchanged, the new tests assert the EgressRefusedError type, and the public-redirect control cases keep the metadata cases from passing for the wrong reason. The spy fails closed on unexpected hosts, and globalThis.fetch is restored in afterEach.

@nc9 nc9 mentioned this pull request Oct 26, 2026
@nc9

nc9 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Landed in the v0.0.135 batch (#1151), main commits 25dbf78..b364cdc.

@nc9 nc9 closed this Oct 26, 2026
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