-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement content security policy (#698)
Fix #486
- Loading branch information
1 parent
0b79879
commit 29ba0ac
Showing
4 changed files
with
47 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CspController < ApplicationController | ||
skip_before_action :verify_authenticity_token | ||
skip_before_action :authenticate_user | ||
|
||
def violation_report | ||
Rails.logger.info(request.body.read) | ||
head :ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rails_helper' | ||
|
||
describe CspController do | ||
describe '/csp-violation-report' do | ||
it 'records the violation' do | ||
body = { | ||
"csp-report" => { | ||
"blocked-uri" => "data", | ||
"document-uri" => "http://localhost:3000/s/izi825/hckr_news_hacker_news_sorted_by_time", | ||
"original-policy" => [ | ||
"default-src 'none'", | ||
"img-src *", | ||
"script-src 'self' 'unsafe-inline'", | ||
"style-src 'self' 'unsafe-inline'", | ||
"form-action 'self'", | ||
"report-uri http://localhost:3000/csp-violation-report", | ||
].join('; '), | ||
"referrer" => "http://localhost:3000/", | ||
"violated-directive" => "img-src", | ||
}, | ||
} | ||
post :violation_report, body: body.to_json, format: :json | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
end |