Automatically generate a CSP for your site.
cspresso crawls up to N same‑origin pages with headless Chromium (Playwright), watches the assets that load,
and emits a draft Content-Security-Policy header.
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
cspresso lets the browser do the hard part: execute the page, watch what it loads, and distill origins into directives.
It uses Playwright (a tool designed to run a browser in 'headless' mode, originally to help automate performing frontend testing of websites) to visit the website in the background and learn what directives of a Content-Security Policy would be needed in order to set such a header and still have the website function properly.
It can also evaluate a provided CSP against a site and see if normal use of the site would trigger violations of the policy, before you ship it.
--max-pages same-origin pages and let the app’s JS run.Popular flags
A few options that tend to matter in real deployments.
connect-src.upgrade-insecure-requests in the proposed policy.Install
pipx, pip, Poetry, or a standalone AppImage from Releases.
# Recommended
pipx install cspresso
# Or plain pip (use a venv)
pip install cspresso
./.pw-browsers
for deterministic builds and easy CI caching.
--browsers-path or PLAYWRIGHT_BROWSERS_PATH.
poetry add cspresso
--with-deps (may require elevated privileges).
chmod +x cspresso.AppImage
./cspresso.AppImage https://example.com \
--browsers-path "$HOME/.cache/cspresso/pw-browsers"
--browsers-path to install browsers into a writable cache directory.
00AE817C24A10C2540461A9C1D7CDE0234DB458D).