Skip to content

chore(waf-detect): capture and sanitise WAF block-page samples #1328 - #1809

Closed
nc9 wants to merge 2 commits into
mainfrom
r3/waf-sample-capture-1328
Closed

nc9 wants to merge 2 commits into
mainfrom
r3/waf-sample-capture-1328

Conversation

@nc9

@nc9 nc9 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1328, #1258. Not a close: detection for Netlify and Fastly Next-Gen WAF stays open until real samples exist (Nik is setting up throwaway sites).

What this adds

Dev tooling only. packages/waf-detect/scripts/capture-block-sample.ts fetches one URL, keeps the status and headers and the body, and writes a JSON fixture shaped like the Sample type in packages/waf-detect/tests/fixtures/waf-blocks.ts (how: "live").

  • Fetch uses redirect: "manual" so the block page itself is captured, with no credentials and a timeout. The fetch implementation is injected; the test passes a fake one and nothing touches the network. The request sends only user-agent and accept: no authorization or cookie header, and a test guards that.
  • Refuses non-http(s) URLs and URLs with embedded credentials before any request.
  • Sanitising:
    • set-cookie is dropped (counted).
    • Client-IP headers (x-forwarded-for, cf-connecting-ip, x-nf-client-connection-ip, fastly-client-ip, and others) are replaced whole by REDACTED-IP.
    • Request-id headers keep their name, with the value replaced by REDACTED-REQUEST-ID: x-nf-request-id, x-sigsci-requestid, x-amz-cf-id, cf-ray, x-served-by (names the cache node), and others.
    • Every *.netlify.app origin is replaced by example.com in bodies and headers, not only the captured host. The provider's own netlify.com pages are kept, since they are evidence.
    • An absolute Location has its host replaced by example.com whatever the host is, with any userinfo removed. A relative Location is kept.
    • In header values and the body, the request host becomes example.com, IPv4 and IPv6 addresses become REDACTED-IP, UUIDs and long hex runs become REDACTED-ID, and token-like pairs become REDACTED-TOKEN. Other x-sigsci-* values keep their text and lose only the id-shaped part.
    • Every category is counted in redactions.
  • Refuses to overwrite --out without --force. Body capped at 256 KiB, with truncated recorded.
  • The output still needs a human read before it is committed: redaction is pattern based.

Not scrubbed, by design: third-party hosts in the body (CDN and asset URLs), since markup is what detection is tested against. Token pairs in headers are not scrubbed either; only bodies get them.

Acceptance (for this tooling step)

  • Sample capture tooling exists and writes a fixture in the Sample shape: done, see the script header.
  • Sanitising keeps the status, the provider headers and the body, and strips cookies, IPs, request ids and origin hostnames: covered by capture-block-sample.test.ts > sanitises headers and body and leaks neither host nor ip, replaces every *.netlify.app origin in the body and Location, not only the target, and replaces the host of any absolute Location and keeps a relative one.
  • Redacted id headers and client-IP headers: redacts cf-ray and x-amz-cf-id values and keeps their names, replaces Netlify and Fastly client-IP headers whole, whatever their value looks like, and redacts only the id part of x-sigsci headers.
  • IPv6 scrubbing, with times and CSS left alone: scrubs IPv6 addresses but leaves times and CSS pseudo-elements alone.
  • Not part of this PR: the two real samples (Netlify and Fastly) and any detection change. Both remain open on Collect real Netlify and Fastly Next-Gen WAF block-page samples #1328.

Gates

  • bun test ./packages/waf-detect/tests/capture-block-sample.test.ts: 12 pass, 0 fail
  • Break-the-test check: the new and changed tests were run against the previous script (git show HEAD~1:...): 5 fail, as expected. The IPv6 test passes on both, since IPv6 scrubbing already existed; it guards that behaviour.
  • tsgo on the script and test (temporary tsconfig in /tmp, bun types): exit 0
  • oxfmt --check on both files: exit 0
  • oxlint with default config on both files: no findings. The repo config apps/cli/oxlint.config.mjs fails before and after this change with Rule 'react-compiler' not found in plugin 'react', so it is not a usable gate here.

Scope

  • docs/ and CHANGELOG.md: not touched. This is not user-facing.
  • Squirrelscan agent skill: no change needed.
  • Private rule catalog: no regeneration needed, no rule meta changed.

Docs: none. Skill: none.

Review of the capture tool found gaps in what it scrubs before a sample
can be committed:

- x-served-by names the cache node, so its value is now redacted (the
  name stays as evidence).
- x-amz-cf-id joins the request-id headers.
- x-nf-client-connection-ip and fastly-client-ip join the client-IP
  headers, so their values are replaced whole.
- Every *.netlify.app origin is replaced in bodies and headers, not only
  the captured host. app.netlify.com is kept, as provider evidence.
- An absolute Location has its host replaced whatever the host is, with
  userinfo removed. A relative Location is kept.

The request sends no authorization or cookie header; a test now guards
that. Tests cover IPv6 (and keep times and CSS alone), cf-ray,
x-amz-cf-id, and each item above. Five of the tests (the flipped x-served-by case and four new ones) fail on the
previous script.

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

nc9 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded: this change is on main via separate merges (rebasing bundle #1814 onto main skipped every code commit from #1810/#1806/#1809/#1812 as already applied).

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.

2 participants