Skip to content

Commit bc25f5c

Browse files
committed
Revert some unnecessary changes that broke things
1 parent d41d3ba commit bc25f5c

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ source 'https://rubygems.org'
33
gemspec
44

55
group :test do
6-
gem 'pry'
76
gem 'test-unit', '~> 3.0'
87
gem 'rails', '3.2.22'
98
gem 'sqlite3', :platforms => [:ruby, :mswin, :mingw]

lib/secure_headers/headers/content_security_policy.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'securerandom'
44
require 'user_agent_parser'
55
require 'json'
6-
require 'pry'
76

87
module SecureHeaders
98
class ContentSecurityPolicyBuildError < StandardError; end
@@ -68,7 +67,6 @@ module Constants
6867
).freeze
6968

7069
ALL_DIRECTIVES = [DIRECTIVES_1_0 + DIRECTIVES_2_0 + DIRECTIVES_3_0 + DIRECTIVES_DRAFT].flatten.sort.uniq
71-
ALL_CONFIGS = [:enforce, :app_name, :script_hash_middleware] + ALL_DIRECTIVES
7270
CONFIG_KEY = :csp
7371
end
7472

@@ -136,26 +134,26 @@ def initialize(config=nil, options={})
136134
@ssl_request = !!options.delete(:ssl)
137135
@request_uri = options.delete(:request_uri)
138136
@http_additions = config.delete(:http_additions)
137+
@disable_img_src_data_uri = !!config.delete(:disable_img_src_data_uri)
138+
@tag_report_uri = !!config.delete(:tag_report_uri)
139+
@script_hashes = config.delete(:script_hashes) || []
139140
@app_name = config.delete(:app_name)
140141
@app_name = @app_name.call(@controller) if @app_name.respond_to?(:call)
141142
@enforce = config.delete(:enforce)
142143
@enforce = @enforce.call(@controller) if @enforce.respond_to?(:call)
143144
@enforce = !!@enforce
144-
@disable_img_src_data_uri = !!config.delete(:disable_img_src_data_uri)
145-
@tag_report_uri = !!config.delete(:tag_report_uri)
146-
@script_hashes = config.delete(:script_hashes) || []
147145

148146
# Config values can be string, array, or lamdba values
149147
@config = config.inject({}) do |hash, (key, value)|
150148
config_val = value.respond_to?(:call) ? value.call(@controller) : value
151-
if ContentSecurityPolicy::ALL_CONFIGS.include?(key.to_sym) # directives need to be normalized to arrays of strings
149+
if ALL_DIRECTIVES.include?(key.to_sym) # directives need to be normalized to arrays of strings
152150
config_val = config_val.split if config_val.is_a? String
153151
if config_val.is_a?(Array)
154152
config_val = config_val.map do |val|
155153
translate_dir_value(val)
156154
end.flatten.uniq
157155
end
158-
else
156+
elsif key != :script_hash_middleware
159157
raise ArgumentError.new("Unknown directive supplied: #{key}")
160158
end
161159

@@ -219,7 +217,9 @@ def value
219217
def to_json
220218
build_value
221219
@config.inject({}) do |hash, (key, value)|
222-
hash[key.to_s.gsub(/(\w+)_(\w+)/, "\\1-\\2")] = value
220+
if ALL_DIRECTIVES.include?(key)
221+
hash[key.to_s.gsub(/(\w+)_(\w+)/, "\\1-\\2")] = value
222+
end
223223
hash
224224
end.to_json
225225
end

0 commit comments

Comments
 (0)