See what your Symfony CSP blocks
To see what your Symfony Content Security Policy blocks, set report-uri in NelmioSecurityBundle's CSP config to http://localhost:8000/csp/shop. The browser then posts every violation to Buggregator, and you read the directive, the blocked resource and the page in one feed. Start in report-only mode, so nothing is blocked while you write the policy.
Steps
1. Start Buggregator
Port 8000 is the web UI and the report endpoint.
docker run --pull always \
-p 127.0.0.1:8000:8000 \
ghcr.io/buggregator/server:latest2. Add a report-only policy for dev
In NelmioSecurityBundle, the report section sends the policy as report-only: the browser reports violations but blocks nothing. Put it in a dev-only config file, for example config/packages/dev/nelmio_security.yaml.
nelmio_security:
csp:
report:
report-uri: 'http://localhost:8000/csp/shop'
default-src: [ 'self' ]
script-src: [ 'self' ]
img-src: [ 'self' ]shop is the Buggregator project key. Leave out /shop to send reports to the default project.
3. Load your pages
Open your app in the browser and click through it. Every script, style or image the policy does not allow is reported. Use localhost:8000 in the policy, not a Docker service name: the browser sends the report, not your app.
4. Read the reports
Open http://localhost:8000. The feed gets one card per report request: the page, then one line per violation, for example «script-src-elem blocked cdn.example.com/x.js». Report-only violations get a badge. The event page shows the directive, the blocked resource, the file with line and column, the code sample, the full policy and the raw report. CSP reports in the menu lists only these events.
5. Check it without a browser
Send one report with curl to see that Buggregator receives it.
curl -X POST http://localhost:8000/csp/shop \
-H 'Content-Type: application/csp-report' \
-d '{"csp-report":{"document-uri":"https://shop.test/checkout","effective-directive":"script-src-elem","blocked-uri":"https://cdn.example.com/x.js","disposition":"enforce"}}'Why it works
NelmioSecurityBundle writes your config as a Content-Security-Policy-Report-Only header with the report-uri you set. When the page breaks the policy, the browser POSTs a JSON report to that address. Buggregator accepts reports at /csp/<project>, answers the browser's CORS check, and stores each report as an event. Once the feed stays empty, move the rules to the enforce section.
Docs: docs.buggregator.dev/config/csp.html#report-uri-works-everywhere
Requires Buggregator v2.13.0+
Related tips
- CSP
See what your Content-Security-Policy blocks, in one feed
Add report-uri pointing at Buggregator to your CSP header. Every violation shows with the blocked URL, the directive and the policy. Any site.
- CSP
See what your Laravel CSP blocks
Set CSP_REPORT_URI in spatie/laravel-csp to Buggregator. Every Content Security Policy violation shows up in one feed while you write the policy.
- CSP
Catch browser deprecation reports before a feature breaks
Name Buggregator as the default Reporting API endpoint. The browser's deprecation and intervention reports land in the same feed as CSP violations.
- Sentry
Symfony errors in a Sentry-style view, no account
Install sentry/sentry-symfony, turn it on for dev and set SENTRY_DSN to Buggregator. Exceptions show with stack trace, request and breadcrumbs.
Checked on with Buggregator v2.13.0