Skip to content

Commit 7915516

Browse files
committed
Merge pull request #202 from twitter/2.x-deprecation-warnings
2.x deprecation warnings
2 parents 8e0e654 + f46a160 commit 7915516

17 files changed

+52
-11
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ rvm:
99

1010
sudo: false
1111
cache: bundler
12+
before_install: gem update bundler

Gemfile

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

55
group :test do
6+
gem "guard-rspec", platforms: [:ruby_19, :ruby_20, :ruby_21, :ruby_22]
67
gem 'test-unit', '~> 3.0'
78
gem 'rails', '3.2.22'
89
gem 'sqlite3', :platforms => [:ruby, :mswin, :mingw]

Guardfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
guard :rspec, cmd: "bundle exec rspec", all_on_start: true, all_after_pass: true do
2+
require "guard/rspec/dsl"
3+
dsl = Guard::RSpec::Dsl.new(self)
4+
5+
# RSpec files
6+
rspec = dsl.rspec
7+
watch(rspec.spec_helper) { rspec.spec_dir }
8+
watch(rspec.spec_support) { rspec.spec_dir }
9+
watch(rspec.spec_files)
10+
11+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
12+
end

fixtures/rails_3_2_22_no_init/app/controllers/other_things_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def other_action
99
end
1010

1111
def secure_header_options_for(header, options)
12+
warn "[DEPRECATION] secure_header_options_for will not be supported in secure_headers 3.x."
1213
if params[:action] == "other_action"
1314
if header == :csp
1415
options.merge(:style_src => "'self'")

lib/secure_headers.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@ class << self
3333
:x_xss_protection, :csp, :x_download_options, :script_hashes,
3434
:x_permitted_cross_domain_policies, :hpkp
3535

36-
def configure &block
36+
# For preparation for the secure_headers 3.x change.
37+
def default &block
3738
instance_eval &block
3839
if File.exists?(SCRIPT_HASH_CONFIG_FILE)
3940
::SecureHeaders::Configuration.script_hashes = YAML.load(File.open(SCRIPT_HASH_CONFIG_FILE))
4041
end
4142
end
43+
44+
def configure &block
45+
warn "[DEPRECATION] `configure` is removed in secure_headers 3.x. Instead use `default`."
46+
default &block
47+
end
4248
end
4349
end
4450

lib/secure_headers/headers/content_security_policy.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,18 @@ def initialize(config=nil, options={})
137137

138138
# Config values can be string, array, or lamdba values
139139
@config = config.inject({}) do |hash, (key, value)|
140-
config_val = value.respond_to?(:call) ? value.call(@controller) : value
140+
config_val = if value.respond_to?(:call)
141+
warn "[DEPRECATION] secure_headers 3.x will not support procs as config values."
142+
value.call(@controller)
143+
else
144+
value
145+
end
146+
141147
if ALL_DIRECTIVES.include?(key.to_sym) # directives need to be normalized to arrays of strings
142-
config_val = config_val.split if config_val.is_a? String
148+
if config_val.is_a? String
149+
warn "[DEPRECATION] A String was supplied for directive #{key}. secure_headers 3.x will require all directives to be arrays of strings."
150+
config_val = config_val.split
151+
end
143152
if config_val.is_a?(Array)
144153
config_val = config_val.map do |val|
145154
translate_dir_value(val)
@@ -258,10 +267,10 @@ def append_http_additions
258267

259268
def translate_dir_value val
260269
if %w{inline eval}.include?(val)
261-
warn "[DEPRECATION] using inline/eval may not be supported in the future. Instead use 'unsafe-inline'/'unsafe-eval' instead."
270+
warn "[DEPRECATION] using inline/eval is not suppored in secure_headers 3.x. Instead use 'unsafe-inline'/'unsafe-eval' instead."
262271
val == 'inline' ? "'unsafe-inline'" : "'unsafe-eval'"
263272
elsif %{self none}.include?(val)
264-
warn "[DEPRECATION] using self/none may not be supported in the future. Instead use 'self'/'none' instead."
273+
warn "[DEPRECATION] using self/none is not suppored in secure_headers 3.x. Instead use 'self'/'none' instead."
265274
"'#{val}'"
266275
elsif val == 'nonce'
267276
if supports_nonces?

lib/secure_headers/headers/strict_transport_security.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def value
4141

4242
def validate_config
4343
if @config.is_a? Hash
44+
warn "[DEPRECATION] secure_headers 3.0 will only accept string values for StrictTransportSecurity config"
4445
if !@config[:max_age]
4546
raise STSBuildError.new("No max-age was supplied.")
4647
elsif @config[:max_age].to_s !~ /\A\d+\z/

lib/secure_headers/headers/x_content_type_options.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def value
2525
when String
2626
@config
2727
else
28+
warn "[DEPRECATION] secure_headers 3.0 will only accept string values for XContentTypeOptions config"
2829
@config[:value]
2930
end
3031
end

lib/secure_headers/headers/x_download_options.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def value
2424
when String
2525
@config
2626
else
27+
warn "[DEPRECATION] secure_headers 3.0 will only accept string values for XDownloadOptions config"
2728
@config[:value]
2829
end
2930
end

lib/secure_headers/headers/x_frame_options.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def value
2525
when String
2626
@config
2727
else
28+
warn "[DEPRECATION] secure_headers 3.0 will only accept string values for XFrameOptions config"
2829
@config[:value]
2930
end
3031
end

0 commit comments

Comments
 (0)