Skip to content

Commit

Permalink
enforce content security policy (lobsters#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdziedzic authored and pushcx committed Sep 11, 2019
1 parent a323dc2 commit 57cf63d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
# Report CSP violations to a specified URI
# For further information see the following documentation:
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
Rails.application.config.content_security_policy_report_only = true
Rails.application.config.content_security_policy_report_only = false
18 changes: 18 additions & 0 deletions spec/requests/content_security_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rails_helper'

describe 'content security policy' do
it 'sets the correct headers' do
get '/'

directives = [
"default-src 'none'",
"img-src * data:",
"script-src 'self' 'unsafe-inline'",
"style-src 'self' 'unsafe-inline'",
"form-action 'self'",
"report-uri /csp-violation-report",
].join('; ')

expect(response.headers['Content-Security-Policy']).to eq(directives)
end
end

0 comments on commit 57cf63d

Please sign in to comment.