Skip to content

Commit 647cb49

Browse files
committed
update readme to include reporting info
1 parent e2fffdf commit 647cb49

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,50 @@ SecureHeaders::Configuration.default do |config|
8888
img_src: %w(somewhereelse.com),
8989
report_uri: %w(https://report-uri.io/example-csp-report-only)
9090
})
91+
92+
# Optional: Use the modern report-to directive (with Reporting-Endpoints header)
93+
config.csp = config.csp.merge({
94+
report_to: "csp-endpoint"
95+
})
96+
97+
# When using report-to, configure the reporting endpoints header
98+
config.reporting_endpoints = {
99+
"csp-endpoint": "https://report-uri.io/example-csp",
100+
"csp-report-only": "https://report-uri.io/example-csp-report-only"
101+
}
91102
end
92103
```
93104

105+
### CSP Reporting
106+
107+
SecureHeaders supports both the legacy `report-uri` and the modern `report-to` directives for CSP violation reporting:
108+
109+
#### report-uri (Legacy)
110+
The `report-uri` directive sends violations to a URL endpoint. It's widely supported but limited to POST requests with JSON payloads.
111+
112+
```ruby
113+
config.csp = {
114+
default_src: %w('self'),
115+
report_uri: %w(https://example.com/csp-report)
116+
}
117+
```
118+
119+
#### report-to (Modern)
120+
The `report-to` directive specifies a named reporting endpoint defined in the `Reporting-Endpoints` header. This enables more flexible reporting through the HTTP Reporting API standard.
121+
122+
```ruby
123+
config.csp = {
124+
default_src: %w('self'),
125+
report_to: "csp-endpoint"
126+
}
127+
128+
config.reporting_endpoints = {
129+
"csp-endpoint": "https://example.com/reports"
130+
}
131+
```
132+
133+
**Recommendation:** Use both `report-uri` and `report-to` for maximum compatibility while transitioning to the modern approach.
134+
94135
### Deprecated Configuration Values
95136
* `block_all_mixed_content` - this value is deprecated in favor of `upgrade_insecure_requests`. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/block-all-mixed-content for more information.
96137

0 commit comments

Comments
 (0)