Skip to content

Commit b4b2192

Browse files
committed
remove concept of non-default sources
1 parent 11bb60b commit b4b2192

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,23 @@ The following methods are going to be called, unless they are provided in a `ski
4242
config.x_download_options = 'noopen'
4343
config.x_permitted_cross_domain_policies = 'none'
4444
config.csp = {
45-
:default_src => "https: self",
45+
:default_src => "https: 'self'",
4646
:enforce => proc {|controller| controller.current_user.enforce_csp? },
4747
:frame_src => "https: http:.twimg.com http://itunes.apple.com",
4848
:img_src => "https:",
49+
:connect_src => "wws:"
50+
:font_src => "'self' data:",
51+
:frame_src => "'self'",
52+
:img_src => "mycdn.com data:",
53+
:media_src => "utoob.com",
54+
:object_src => "'self'",
55+
:script_src => "'self'",
56+
:style_src => "'unsafe-inline'",
57+
:base_uri => "'self'",
58+
:child_src => "'self'",
59+
:form_action => "'self' github.com",
60+
:frame_ancestors => "'none'",
61+
:plugin_types => 'application/x-shockwave-flash',
4962
:report_uri => '//example.com/uri-directive'
5063
}
5164
config.hpkp = {

lib/secure_headers/headers/content_security_policy.rb

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,19 @@ module Constants
2020
:media_src,
2121
:object_src,
2222
:script_src,
23-
:style_src
24-
]
25-
26-
NON_DEFAULT_SOURCES = [
23+
:style_src,
2724
:base_uri,
2825
:child_src,
2926
:form_action,
3027
:frame_ancestors,
31-
:plugin_types,
32-
:referrer,
33-
:reflected_xss
28+
:plugin_types
3429
]
3530

3631
OTHER = [
3732
:report_uri
3833
]
3934

40-
SOURCE_DIRECTIVES = DIRECTIVES + NON_DEFAULT_SOURCES
41-
42-
ALL_DIRECTIVES = DIRECTIVES + NON_DEFAULT_SOURCES + OTHER
35+
ALL_DIRECTIVES = DIRECTIVES + OTHER
4336
CONFIG_KEY = :csp
4437
end
4538

@@ -111,7 +104,7 @@ def initialize(config=nil, options={})
111104
@config = config.inject({}) do |hash, (key, value)|
112105
config_val = value.respond_to?(:call) ? value.call(@controller) : value
113106

114-
if SOURCE_DIRECTIVES.include?(key) # directives need to be normalized to arrays of strings
107+
if DIRECTIVES.include?(key) # directives need to be normalized to arrays of strings
115108
config_val = config_val.split if config_val.is_a? String
116109
if config_val.is_a?(Array)
117110
config_val = config_val.map do |val|
@@ -191,7 +184,6 @@ def build_value
191184
append_http_additions unless ssl_request?
192185
header_value = [
193186
generic_directives,
194-
non_default_directives,
195187
report_uri_directive
196188
].join.strip
197189
end
@@ -258,15 +250,6 @@ def generic_directives
258250
header_value
259251
end
260252

261-
def non_default_directives
262-
header_value = ''
263-
NON_DEFAULT_SOURCES.each do |directive_name|
264-
header_value += build_directive(directive_name) if @config[directive_name]
265-
end
266-
267-
header_value
268-
end
269-
270253
def build_directive(key)
271254
"#{self.class.symbol_to_hyphen_case(key)} #{@config[key].join(" ")}; "
272255
end

spec/lib/secure_headers/headers/content_security_policy_spec.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,6 @@ def request_for user_agent, request_uri=nil, options={:ssl => false}
148148
}.to raise_error(RuntimeError)
149149
end
150150

151-
context "CSP level 2 directives" do
152-
let(:config) { {:default_src => 'self'} }
153-
::SecureHeaders::ContentSecurityPolicy::Constants::NON_DEFAULT_SOURCES.each do |non_default_source|
154-
it "supports all level 2 directives" do
155-
directive_name = ::SecureHeaders::ContentSecurityPolicy.send(:symbol_to_hyphen_case, non_default_source)
156-
config.merge!({ non_default_source => "value" })
157-
csp = ContentSecurityPolicy.new(config, :request => request_for(CHROME))
158-
expect(csp.value).to match(/#{directive_name} value;/)
159-
end
160-
end
161-
end
162-
163151
context "auto-whitelists data: uris for img-src" do
164152
it "sets the value if no img-src specified" do
165153
csp = ContentSecurityPolicy.new({:default_src => 'self'}, :request => request_for(CHROME))

0 commit comments

Comments
 (0)