Reporting CSP errors | laravel-csp-rust | Spatie       

 SPATIE  

laravel-csp-rust
================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-csp-rust](https://spatie.be/docs/laravel-csp-rust/v1)  Reporting CSP errors

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-csp-rust/v1) 

  Reporting CSP errors    
- [ Introduction ](https://spatie.be/docs/laravel-csp-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-csp-rust/v1/support-us)
- [ Installation and setup ](https://spatie.be/docs/laravel-csp-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-csp-rust/v1/usage)
- [ Creating a preset ](https://spatie.be/docs/laravel-csp-rust/v1/creating-a-preset)
- [ Using inline scripts and styles ](https://spatie.be/docs/laravel-csp-rust/v1/using-inline-scripts-and-styles)
- [ Outputting a CSP policy as a meta tag ](https://spatie.be/docs/laravel-csp-rust/v1/outputting-a-csp-policy-as-a-meta-tag)
- [ Reporting CSP errors ](https://spatie.be/docs/laravel-csp-rust/v1/reporting-csp-errors)
- [ Testing ](https://spatie.be/docs/laravel-csp-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-csp-rust/v1/changelog)
- [ Releasing ](https://spatie.be/docs/laravel-csp-rust/v1/releasing)

 Reporting CSP errors
====================

###  On this page 

1. [ In the browser ](#content-in-the-browser)
2. [ To an external URL ](#content-to-an-external-url)

In the browser
--------------------------------------------------------------------------------------------------

Instead of outright blocking violations, configure a report-only policy. Requests will still be made, but violations appear in the browser's console. This is useful for trying a new policy without breaking your site.

```
config.report_only.preset(Basic);
config.report_only.directives.add(Directive::Script, Keyword::StrictDynamic)?;
```

The enforcing policy still applies. To run only in report-only mode, clear `config.policy.presets` and leave its directives empty. An empty policy does not emit a header, even when reporting settings are present.

To an external URL
--------------------------------------------------------------------------------------------------------------

Violations can be reported to an endpoint. There are two directives:

- `report-uri` is deprecated but remains supported by many browsers. Set `report_uri` or `CSP_REPORT_URI`.
- `report-to` names an endpoint in the `Reporting-Endpoints` header. Set `report_to` or `CSP_REPORT_TO`, then define the endpoint URL in `reporting_endpoints`.

You can configure both during the transition:

```
config.report_uri = "https://example.com/csp-reports".into();
config.report_to = "default".into();
config.reporting_endpoints.push(("default".into(), "https://example.com/csp-reports".into()));
```

[Report URI](https://report-uri.com/) is a service built for receiving violation reports. The package sets reporting headers; it does not install a report receiver. If you host your own endpoint, accept untrusted JSON reports, limit request sizes and rate-limit submissions.

To use separate enforcing and report-only endpoints, set `report_only_uri` and `report_only_to` (or `CSP_REPORT_ONLY_URI` and `CSP_REPORT_ONLY_TO`). An empty value falls back to `report_uri` or `report_to`. Define both endpoint names in `reporting_endpoints` when using separate Reporting API groups.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
