header-replay
<p align="center">
<img src="docs/icon.png" alt="header-replay icon" width="96" height="96">
</p>
# header-replay
**Rehearse HTTP security headers in a real browser before you ship them.**
[](https://github.com/htsecurity/header-replay/actions/workflows/ci.yml)
[](LICENSE)
[](https://www.python.org/)
`header-replay` opens your page in Chromium, applies candidate response headers
locally, and compares it with the real response. It shows CSP violations,
failed requests, JavaScript errors and before/after screenshots, then suggests
the smallest policy change that would unblock the page.
No server changes. No proxy. No deploy-and-pray.
<p align="center">
<img src="docs/report.png" alt="header-replay HTML report with baseline and candidate screenshots" width="900">
</p>
## Why
A security-header scanner can tell you that a header is missing. It cannot tell
you whether fixing it will break login, checkout, analytics or a third-party
widget. That is why CSP rollouts stall.
`header-replay` tests the browser behavior directly:
1. Load the real page as a baseline.
2. Load it again with your candidate headers injected into every response.
3. Capture CSP violation events, failed requests and JavaScript errors.
4. Report only issues that appear with the candidate policy.
5. Export a self-contained HTML report with evidence and screenshots.
## Install
With [uv](https://docs.astral.sh/uv/):
```sh
uv tool install git+https://github.com/htsecurity/header-replay.git
header-replay setup
```
`setup` downloads the Chromium build used by Playwright. On Linux, use
`header-replay setup --with-deps` if the system libraries are missing.
Or with pipx:
```sh
pipx install git+https://github.com/htsecurity/header-replay.git
header-replay setup
```
## Usage
See what a site currently sends:
```sh
header-replay scan https://example.com
header-replay scan https://example.com --json
```
Test a CSP without touching the server:
```sh
header-replay simulate https://example.com \
--csp "default-src 'self'; script-src 'self'; object-src 'none'"
```
Test an HSTS value or several headers:
```sh
header-replay simulate https://example.com \
--hsts \
--header "X-Content-Type-Options: nosniff" \
--header "Referrer-Policy: strict-origin-when-cross-origin"
```
Start from a practical baseline set:
```sh
header-replay simulate https://example.com --strict-baseline
```
Generate an HTML report:
```sh
header-replay simulate https://example.com \
--csp "default-src 'self'; script-src 'self'" \
--format html --output header-report.html
```
Use a headers file:
```json
{
"Content-Security-Policy": "default-src 'self'; script-src 'self'",
"X-Content-Type-Options": "nosniff"
}
```
```sh
header-replay simulate https://example.com --headers-file headers.json
```
Test a local app:
```sh
header-replay simulate http://localhost:3000 \
--allow-private \
--csp "default-src 'self'; script-src 'self'"
```
### Output formats
- `text`: terminal summary and recommendations.
- `json`: full structured report for automation.
- `html`: self-contained report with before/after screenshots.
Exit codes:
- `0`: no new browser issue observed.
- `1`: the candidate caused new CSP violations, failed requests or JS errors.
- `2`: invalid input, network/browser error or AI configuration error.
## AI review (real models, optional)
The simulation is deterministic. AI is only used when you ask for a second
opinion:
```sh
# Local first
header-replay simulate https://example.com --csp "default-src 'self'" --ai-review
# Specific local model
header-replay simulate https://example.com --csp "default-src 'self'" \
--ai-review --ai-provider ollama --model qwen2.5:14b
# OpenRouter
export OPENROUTER_API_KEY=...
header-replay simulate https://example.com --csp "default-src 'self'" \
--ai-review --ai-provider openrouter
```
The model receives the candidate headers, violations and recommendations, not
the page HTML or screenshots. It returns structured JSON with a risk level,
whether the policy looks safe for the tested flow, and concrete changes.
Example from a real local run:
```text
AI review (ollama/qwen2.5:14b): medium risk · safe_to_deploy=False
The current CSP blocks necessary resources and inline scripts, leading to
functional issues.
```
That run used 1,269 prompt tokens and 191 completion tokens. The `models`
command lists local Ollama models and live OpenRouter models with prices:
```sh
header-replay models --provider openrouter
```
## MCP server
`header-replay` exposes the same functionality to Claude, Cursor and other MCP
clients:
| Tool | Purpose |
| --- | --- |
| `scan(url)` | Read the current response headers. |
| `simulate_headers(url, headers, ...)` | Run a real-browser before/after simulation. |
| `review(report, provider?, model?)` | Ask a real LLM to review the simulation. |
| `security_headers()` | List headers and recommended starting values. |
| `models(provider?)` | List local and hosted models. |
Claude Code:
```sh
claude mcp add header-replay -- uvx --from git+https://github.com/htsecurity/header-replay header-replay-mcp
```
Claude Desktop / Cursor:
```json
{
"mcpServers": {
"header-replay": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/htsecurity/header-replay",
"header-replay-mcp"
]
}
}
}
```
Run `header-replay setup` once before using the MCP server so Chromium is
available.
## GitHub Action
Test a preview deployment before merging:
```yaml
- uses: htsecurity/header-replay@v0.1.0
with:
url: https://preview.example.com
headers: '{"Content-Security-Policy":"default-src ''self''; script-src ''self'' ''https://cdn.example.com''"}'
fail-on-violation: true
```
For local/private preview URLs, set `allow-private: true` only when the runner
can reach that URL and it is your own app.
## Safety
- Only `http://` and `https://` URLs are accepted.
- Public DNS is required by default. Loopback, private, link-local, reserved,
multicast and metadata addresses are blocked to reduce SSRF risk.
- `--allow-private` is explicit and intended for your own local app.
- Every subresource request is checked. Redirects are followed by the browser,
not by a separate crawler.
- Downloads are disabled.
- The tool does not exploit anything, submit forms, log in, or crawl links.
- No telemetry. AI review is opt-in.
## Limitations
- This tests one URL and one browser flow. It does not crawl authenticated areas,
checkout, modals or every route.
- Third-party content can vary between runs. A clean run is evidence, not proof.
- CSP is the strongest signal. HSTS, COOP, CORP and Permissions-Policy still need
deployment-specific verification.
- It does not replace report-only monitoring, cross-browser testing or a full
security review.
- A page can look visually similar while a script is broken. Check the violation
list, not only the screenshots.
## Development
```sh
git clone https://github.com/htsecurity/header-replay.git
cd header-replay
uv sync
uv run playwright install chromium
uv run pytest
uv run ruff check .
uv run ruff format --check .
```
Tests use local HTTP servers and real Chromium runs. No external network access
is required for the test suite.
## License
MIT. See [LICENSE](LICENSE).TDQS
Scored across 5 tools
scan and simulate_headers both take a URL and involve headers, so an agent could briefly hesitate between them, but the descriptions clearly separate read-only inspection from browser-based candidate testing. review, security_headers, and models each target distinct resources with no real overlap.
The set mixes bare verbs (scan, review) with verb_noun compounds (simulate_headers) and noun phrases (security_headers, models). It is still readable, but there is no single predictable pattern an agent can rely on to infer a tool's role from its name alone.
Five tools is well within the healthy range and each maps to a concrete step or lookup in the header-testing workflow. Nothing appears redundant or padded.
The set covers the full core loop: fetch current headers, simulate candidates in a browser, and get an LLM review, plus reference lookups for supported headers and available models. Minor gaps exist (no diff/compare or saved-report retrieval), but the primary workflow has no dead ends.