Generate a Content-Security-Policy for your site.
cspresso crawls up to N same-origin pages with headless Chromium (Playwright), records the assets that load,
and emits a draft Content-Security-Policy header with evidence to review.
pipx install cspresso
cspresso https://mig5.net --max-pages 10
# visited: https://mig5.net/
Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.jsdelivr.net; ...;
How it works
Playwright runs the site in a headless browser, and cspresso records what the page loads into a draft policy.
- Crawl: visit up to
--max-pagessame-origin pages and let the application's JavaScript run. - Observe: track scripts, styles, images, fonts, frames, and connect-like requests.
- Draft: emit a baseline policy with evidence for each suggested permission.
- Evaluate: inject a candidate as Report-Only and report any violations.
Inline scripts and styles need care: nonces must be generated per response, and hashes must match bytes exactly. Review and tighten the draft before enforcing it.
Flags
Options for scan scope, output and candidate evaluation.
--bypass-csp- Strip same-origin HTML CSP response headers, not meta CSP. Chromium's process sandbox stays enabled.
--evaluate- Evaluate a policy string or file: exit 1 for completed scans with violations, or 2 for incomplete or failed scans.
--include-sourcemaps- Inspect source-map metadata without automatically granting
connect-srcpermissions. --upgrade-insecure-requests- Emit
upgrade-insecure-requestsin the proposed policy. --browsers-path- Control where Playwright installs Chromium, for AppImage and CI caches.
--json- JSON schema v2: policy evidence, page outcomes, injection confirmation, violations and completeness.
pipx / pip
# Recommended
pipx install cspresso
# Or plain pip (use a venv)
pip install cspresso
cspresso can auto-install missing Chromium binaries into an owned user cache, such as
~/.cache/cspresso/pw-browsers on Linux. Override this with --browsers-path
or PLAYWRIGHT_BROWSERS_PATH. Chromium sandboxing is enabled by default.
Poetry
# From the source checkout, Poetry >=2.2,<3
poetry sync --with dev
poetry run cspresso https://example.com/ --json
From a source checkout, install missing OS libraries with
poetry run playwright install-deps chromium. --with-deps applies when installing
missing browser binaries.
AppImage
chmod +x CSPresso.AppImage
./CSPresso.AppImage https://example.com \
--browsers-path "$HOME/.cache/cspresso/pw-browsers"
AppImages use the writable user-cache default. Choose another owned directory with
--browsers-path if needed. Verify releases with the mig5 GPG key
(fingerprint 54A91143AE0AB4F7743B01FE888ED1B423A3BC99).