Skip to main content
Glama

header-replay

Rehearse HTTP security headers in a real browser before you ship them.

CI License: MIT Python 3.11+

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.

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.

Related MCP server: web-security-guard

Install

With uv:

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:

pipx install git+https://github.com/htsecurity/header-replay.git
header-replay setup

Usage

See what a site currently sends:

header-replay scan https://example.com
header-replay scan https://example.com --json

Test a CSP without touching the server:

header-replay simulate https://example.com \
  --csp "default-src 'self'; script-src 'self'; object-src 'none'"

Test an HSTS value or several headers:

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:

header-replay simulate https://example.com --strict-baseline

Generate an HTML report:

header-replay simulate https://example.com \
  --csp "default-src 'self'; script-src 'self'" \
  --format html --output header-report.html

Use a headers file:

{
  "Content-Security-Policy": "default-src 'self'; script-src 'self'",
  "X-Content-Type-Options": "nosniff"
}
header-replay simulate https://example.com --headers-file headers.json

Test a local app:

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:

# 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:

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:

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:

claude mcp add header-replay -- uvx --from git+https://github.com/htsecurity/header-replay header-replay-mcp

Claude Desktop / Cursor:

{
  "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:

- 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

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.

Available Tools

5 tools
modelsC

List local Ollama models and live OpenRouter models with prices.

Inputs: provider. Returns: object

reviewA

Ask a real LLM to review a simulation report.

The report is sent to the selected provider. Use provider=ollama to keep it on this machine.

Inputs: report (required), model, provider. Returns: object

scanC

Fetch a URL and return its current response headers. Read-only.

Inputs: url (required), allow_private. Returns: object

security_headersA

List supported security headers and recommended starting values.

Inputs: no named parameters. Returns: object

simulate_headersA

Load a URL in Chromium with candidate headers and report browser breakage.

Private/local URLs are blocked unless allow_private is true. Only the exact
URL is tested; this is not a crawler.

Inputs: url (required), headers (required), wait_ms, allow_private, +1 more. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 5 tools

    Disambiguation4/5

    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.

    Naming Consistency3/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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.

    Maintenance

    ActivityMaintained
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers