A Rails engine that collects, stores and notifies on Slack about Content Security Policy (CSP) violation reports.
- Public /csp-reportsendpoint for browsers to POST CSP violations
- Stores CSP reports in a database table
- Tracks notification status with notified_atcolumn
- Optional Slack notifications for CSP violations
- Easy integration with Rails applications
- Ruby >= 3.2
- Rails >= 7.1
- PostgreSQL (for JSONB support)
Add this line to your application's Gemfile:
gem 'reported'And then execute:
$ bundle installOr install it yourself as:
$ gem install reported- Run the install generator:
$ rails generate reported:installThis will create an initializer at config/initializers/reported.rb.
- Run the migrations:
$ rails reported:install:migrations
$ rails db:migrateThis creates the reported_reports table.
The CSP reports endpoint is automatically available at /csp-reports (no mounting required).
Configure your application's CSP to send reports to the endpoint. In config/initializers/content_security_policy.rb:
Rails.application.config.content_security_policy do |policy|
  policy.default_src :self, :https
  policy.script_src  :self, :https
  # ... your other CSP directives ...
  
  # Configure the report URI
  policy.report_uri "/csp-reports"
endTo enable Slack notifications, configure the initializer at config/initializers/reported.rb:
Reported.configuration do |config|
  # Enable or disable Slack notifications
  config.enabled = true
  # Slack webhook URL for notifications
  config.slack_webhook_url = ENV['REPORTED_SLACK_WEBHOOK_URL']
endGet your Slack webhook URL from Slack API.
Set the webhook URL as an environment variable:
REPORTED_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URLOnce configured, the gem automatically:
- Receives CSP violation reports at /reported/csp-reports
- Stores them in the reported_reportstable
- Sends notifications to Slack (if enabled)
- Marks reports as notified with the notified_attimestamp
You can access reports through the Reported::Report model:
# Get all reports
Reported::Report.all
# Get unnotified reports
Reported::Report.not_notified
# Get notified reports
Reported::Report.notified
# Mark a report as notified manually
report = Reported::Report.first
report.mark_as_notified!The reported_reports table includes:
- document_uri- The URI of the document where the violation occurred
- violated_directive- The CSP directive that was violated
- blocked_uri- The URI that was blocked
- original_policy- The complete CSP policy
- raw_report- The complete JSON report from the browser
- notified_at- Timestamp of when the report was sent to Slack
- created_at/- updated_at- Standard timestamps
The gem is available as open source under the terms of the MIT License.