Skip to content

Commit

Permalink
Merge pull request #111 from EiNSTeiN-/xss-protection-report
Browse files Browse the repository at this point in the history
Add report=uri to X-XSS-Protection
  • Loading branch information
oreoshake committed Sep 16, 2014
2 parents cd172b5 + df83776 commit 8caf856
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/secure_headers/headers/x_xss_protection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class XXssProtection < Header
module Constants
X_XSS_PROTECTION_HEADER_NAME = 'X-XSS-Protection'
DEFAULT_VALUE = "1"
VALID_X_XSS_HEADER = /\A[01](; mode=block)?\z/i
VALID_X_XSS_HEADER = /\A[01](; mode=block)?(; report=.*)?\z/i
end
include Constants

Expand All @@ -26,6 +26,7 @@ def value
else
value = @config[:value].to_s
value += "; mode=#{@config[:mode]}" if @config[:mode]
value += "; report=#{@config[:report_uri]}" if @config[:report_uri]
value
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/secure_headers/headers/x_xss_protection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module SecureHeaders
specify { expect(XXssProtection.new.value).to eq("1")}
specify { expect(XXssProtection.new("0").value).to eq("0")}
specify { expect(XXssProtection.new(:value => 1, :mode => 'block').value).to eq('1; mode=block') }
specify { expect(XXssProtection.new(:value => 1, :mode => 'block', :report_uri => 'https://www.secure.com/reports').value).to eq('1; mode=block; report=https://www.secure.com/reports') }

context "with invalid configuration" do
it "should raise an error when providing a string that is not valid" do
Expand Down Expand Up @@ -50,4 +51,4 @@ module SecureHeaders

end
end
end
end

0 comments on commit 8caf856

Please sign in to comment.