Skip to content

Commit

Permalink
Merge pull request #9 from ausaccessfed/feature/dev-to-master
Browse files Browse the repository at this point in the history
Feature/dev to master
  • Loading branch information
phyzical authored Sep 14, 2022
2 parents a53a219 + 267aa8c commit 442b4e8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
publish-gem:
gem build aaf-secure_headers.gemspec
gem push aaf-secure_headers-*.gem
rm aaf-secure_headers-*.gem
8 changes: 4 additions & 4 deletions aaf-secure_headers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'secure_headers', '~> 3.5.0.pre'
spec.add_dependency 'secure_headers'
spec.add_dependency 'activesupport'

spec.add_development_dependency 'bundler', '~> 1.12'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake', '>= 12.3.3'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'actionpack'
end
10 changes: 4 additions & 6 deletions lib/aaf/secure_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ module SecureHeaders
config.cookies = {
secure: true,
httponly: true,
samesite: {
lax: false
}
samesite: ::SecureHeaders::OPT_OUT
}

config.hsts = "max-age=#{6.months.to_i}; includeSubdomains; preload"
Expand All @@ -20,7 +18,7 @@ module SecureHeaders
config.x_xss_protection = '1; mode=block'
config.x_download_options = 'noopen'
config.x_permitted_cross_domain_policies = 'none'
config.referrer_policy = 'no-referrer'
config.referrer_policy = 'strict-origin'

config.csp = {
preserve_schemes: false,
Expand All @@ -40,10 +38,10 @@ module SecureHeaders
end

class <<self
def development_mode!
def development_mode!(use_default_overrides: true)
ensure_rails
insert_dev_middleware
override_dev_configuration
override_dev_configuration if use_default_overrides
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/aaf/secure_headers/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module AAF
module SecureHeaders
VERSION = '2.0.0'.freeze
VERSION = '3.1.0'.freeze
end
end
15 changes: 14 additions & 1 deletion spec/aaf/secure_headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
spy(SecureHeaders::Configuration, csp: csp_config)
end

let(:use_default_overrides) { true }

before do
allow(Rails).to receive_message_chain(:application, :config, :middleware)
.and_return(middleware)
Expand All @@ -20,7 +22,18 @@
end

def run
subject.development_mode!
subject.development_mode!(use_default_overrides: use_default_overrides)
end

context 'when disabling default overrides' do
let(:use_default_overrides) { false }

it 'doesnt override the defaults' do
run
expect(secure_headers_config).not_to have_received(:hsts=).with(nil)
expect(csp_config).not_to have_received(:[]=)
.with(:upgrade_insecure_requests, false)
end
end

it 'raises an exception when Rails is undefined' do
Expand Down

0 comments on commit 442b4e8

Please sign in to comment.