feat(protect): response header-mutation actions (set / remove / harden-cookie) - #111
Merged
Merged
Conversation
…n-cookie)
Add three response-hardening actions so a matched rule mutates the outgoing response's headers
instead of blocking the whole response — the right mitigation for CORS misconfig, security-header
insertion, and cookie hardening:
- `set-header` + `set_headers: {name: value}` — set/overwrite, or `ensure: true` to add only when
absent (don't clobber an existing CSP/X-Frame-Options).
- `remove-header` + `remove_headers: [names]` — strip a header (e.g. Access-Control-Allow-Credentials
on a CORS misconfig, so the response is still served but not cross-origin-readable).
- `harden-cookie` — add missing HttpOnly/Secure/SameSite to Set-Cookie (no duplication;
`cookie_flags` overridable).
Plumbing: header mutations fold into the existing redact-verdict path; a `null` header value now
signals removal in both rebuildResponse (fetch) and the node path; rebuildResponse guards null-body
statuses (204/205/304/101) so hardening a redirect/no-body response doesn't throw. Block-mode-gated
(dry-run observes only), like redact/block. Not a default — authored + route-scoped.
+6 tests; 640 pass; typecheck clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Well-structured header-mutation feature with clear, comprehensive tests. 🎯 Quality: 100% Elite · 📦 Size: Medium 📈 This month: Your 49th PR — above team average · Averaging Excellent |
Contributor
Author
|
/review |
daniloradovic
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Response rules could redact a body span or block the whole response — but for header-based issues (CORS misconfig, missing security headers, weak cookies) "block the whole response" is the wrong tool. This adds header mutation so a rule can strip the offending header and still serve the response.
Completes the output-filtering / hardening story before wiring the pieces together: pairs with
cors_reflected(#110) — detect the misconfig, then stripAccess-Control-Allow-Credentialsrather than 500 the endpoint.What — three actions
set-header+set_headers: { name: value }— set/overwrite;ensure: truesets only when absent (won't clobber an existing CSP / X-Frame-Options).remove-header+remove_headers: [names]— strip named headers.harden-cookie— add missingHttpOnly/Secure/SameSiteto everySet-Cookie(no duplication;cookie_flagsoverrides the defaults).Plumbing
nullheader value now means "delete" — added to bothrebuildResponse(fetch) and the node adapter.rebuildResponsenow guards null-body statuses (204/205/304/101) so hardening a redirect/no-body response doesn't throw.Tests
tests/protect/response-header-mutation.test.ts— 6: remove (CORS strip, served not blocked), set-header ensure (add + don't-clobber), overwrite, harden-cookie (add + no-duplicate), mutation on a 302 (status/Location preserved), dry-run no-op. 640 pass; typecheck clean.Follow-up
Add header-mutation templates to the
triage-vpatch-npmskill (CORS-strip, security-header ensure, cookie-harden) — separate change (skill lives in triage-tools + the hub's vendored copy).🤖 Generated with Claude Code