Skip to content

Commit 6399816

Browse files
committed
Merge pull request #235 from twitter/fix-opt-out-regression
Opting out of all protection would raise an exception because the idempotency check was wrong
2 parents 171ca58 + 0358c8e commit 6399816

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

lib/secure_headers/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def add_noop_configuration
7171
ALL_HEADER_CLASSES.each do |klass|
7272
config.send("#{klass::CONFIG_KEY}=", OPT_OUT)
7373
end
74+
config.dynamic_csp = OPT_OUT
7475
end
7576

7677
add_configuration(NOOP_CONFIGURATION, noop_config)

lib/secure_headers/headers/policy_management.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def validate_config!(config)
196196
# additions = { script_src: %w(google.com)} then idempotent_additions? would return
197197
# because google.com is already in the config.
198198
def idempotent_additions?(config, additions)
199+
return true if config == OPT_OUT && additions == OPT_OUT
199200
return false if config == OPT_OUT
200201
config == combine_policies(config, additions)
201202
end

spec/lib/secure_headers_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module SecureHeaders
3838
ALL_HEADER_CLASSES.each do |klass|
3939
expect(hash[klass::CONFIG_KEY]).to be_nil
4040
end
41+
expect(hash.count).to eq(0)
4142
end
4243

4344
it "allows you to override X-Frame-Options settings" do

0 commit comments

Comments
 (0)