Skip to content

Commit 2801582

Browse files
authored
Merge branch 'main' into feature-7.2
2 parents e5f347e + 6047a2a commit 2801582

26 files changed

+208
-242
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
ruby: [ '2.7', '3.0', '3.1', '3.2', '3.4', '4.0' ]
1414

1515
steps:
16-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v6
1717
- name: Set up Ruby ${{ matrix.ruby }}
18-
uses: ruby/setup-ruby@d697be2f83c6234b20877c3b5eac7a7f342f0d0c #v1.269.0 tag
18+
uses: ruby/setup-ruby@ac793fdd38cc468a4dd57246fa9d0e868aba9085 #v1.269.0 tag
1919
with:
2020
ruby-version: ${{ matrix.ruby }}
2121
bundler-cache: true

.rubocop.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
inherit_gem:
22
rubocop-github:
33
- config/default.yml
4-
require: rubocop-performance
4+
plugins: rubocop-performance
55

66
AllCops:
77
TargetRubyVersion: 2.6
88

99
# Disable cops that are not consistently available across all Ruby versions
10-
Style/ClassMethodsDefinitions:
11-
Enabled: false
12-
13-
Style/OrAssignment:
14-
Enabled: false
15-
16-
Layout/SpaceInsideHashLiteralBraces:
17-
Enabled: false
18-
19-
Lint/ParenthesesAsGroupedExpression:
20-
Enabled: false
21-
2210
Lint/RedundantCopDisableDirective:
2311
Enabled: false

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ NOTE: this version is a breaking change due to the removal of HPKP. Remove the H
7070

7171
## 5.0.0
7272

73-
Well this is a little embarassing. 4.0 was supposed to set the secure/httponly/samesite=lax attributes on cookies by default but it didn't. Now it does. - See the [upgrading to 5.0](docs/upgrading-to-5-0.md) guide.
73+
Well this is a little embarrassing. 4.0 was supposed to set the secure/httponly/samesite=lax attributes on cookies by default but it didn't. Now it does. - See the [upgrading to 5.0](docs/upgrading-to-5-0.md) guide.
7474

7575
## 4.0.1
7676

@@ -194,7 +194,7 @@ end
194194

195195
## 3.4.0 the frame-src/child-src transition for Firefox.
196196

197-
Handle the `child-src`/`frame-src` transition semi-intelligently across versions. I think the code best descibes the behavior here:
197+
Handle the `child-src`/`frame-src` transition semi-intelligently across versions. I think the code best describes the behavior here:
198198

199199
```ruby
200200
if supported_directives.include?(:child_src)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Secure Headers ![Build + Test](https://github.com/github/secure_headers/workflows/Build%20+%20Test/badge.svg?branch=main)
1+
# Secure Headers [![Build + Test](https://github.com/github/secure_headers/actions/workflows/build.yml/badge.svg)](https://github.com/github/secure_headers/actions/workflows/build.yml)
22

33
**main branch represents 7.x line**. See the [upgrading to 4.x doc](docs/upgrading-to-4-0.md), [upgrading to 5.x doc](docs/upgrading-to-5-0.md), [upgrading to 6.x doc](docs/upgrading-to-6-0.md) or [upgrading to 7.x doc](docs/upgrading-to-7-0.md) for instructions on how to upgrade. Bug fixes should go in the `6.x` branch for now.
44

lib/secure_headers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def content_security_policy_style_nonce(request)
184184
content_security_policy_nonce(request, ContentSecurityPolicy::STYLE_SRC)
185185
end
186186

187-
# Public: Retreives the config for a given header type:
187+
# Public: Retrieves the config for a given header type:
188188
#
189189
# Checks to see if there is an override for this request, then
190190
# Checks to see if a named override is used for this request, then
@@ -214,7 +214,7 @@ def raise_on_unknown_target(target)
214214

215215
def config_and_target(request, target)
216216
config = config_for(request)
217-
target = guess_target(config) unless target
217+
target ||= guess_target(config)
218218
raise_on_unknown_target(target)
219219
[config, target]
220220
end

lib/secure_headers/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def default(&block)
6565

6666
# Public: create a named configuration that overrides the default config.
6767
#
68-
# name - use an idenfier for the override config.
68+
# name - use an identifier for the override config.
6969
# base - override another existing config, or override the default config
7070
# if no value is supplied.
7171
#

lib/secure_headers/headers/clear_site_data.rb

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,41 @@ class ClearSiteData
1111
EXECUTION_CONTEXTS = "executionContexts".freeze
1212
ALL_TYPES = [CACHE, COOKIES, STORAGE, EXECUTION_CONTEXTS]
1313

14-
class << self
15-
# Public: make an clear-site-data header name, value pair
16-
#
17-
# Returns nil if not configured, returns header name and value if configured.
18-
def make_header(config = nil, user_agent = nil)
19-
case config
20-
when nil, OPT_OUT, []
21-
# noop
22-
when Array
23-
[HEADER_NAME, make_header_value(config)]
24-
when true
25-
[HEADER_NAME, make_header_value(ALL_TYPES)]
26-
end
14+
# Public: make an clear-site-data header name, value pair
15+
#
16+
# Returns nil if not configured, returns header name and value if configured.
17+
def self.make_header(config = nil, user_agent = nil)
18+
case config
19+
when nil, OPT_OUT, []
20+
# noop
21+
when Array
22+
[HEADER_NAME, make_header_value(config)]
23+
when true
24+
[HEADER_NAME, make_header_value(ALL_TYPES)]
2725
end
26+
end
2827

29-
def validate_config!(config)
30-
case config
31-
when nil, OPT_OUT, true
32-
# valid
33-
when Array
34-
unless config.all? { |t| t.is_a?(String) }
35-
raise ClearSiteDataConfigError.new("types must be Strings")
36-
end
37-
else
38-
raise ClearSiteDataConfigError.new("config must be an Array of Strings or `true`")
28+
def self.validate_config!(config)
29+
case config
30+
when nil, OPT_OUT, true
31+
# valid
32+
when Array
33+
unless config.all? { |t| t.is_a?(String) }
34+
raise ClearSiteDataConfigError.new("types must be Strings")
3935
end
36+
else
37+
raise ClearSiteDataConfigError.new("config must be an Array of Strings or `true`")
4038
end
39+
end
4140

42-
# Public: Transform a clear-site-data config (an Array of Strings) into a
43-
# String that can be used as the value for the clear-site-data header.
44-
#
45-
# types - An Array of String of types of data to clear.
46-
#
47-
# Returns a String of quoted values that are comma separated.
48-
def make_header_value(types)
49-
types.map { |t| %("#{t}") }.join(", ")
50-
end
41+
# Public: Transform a clear-site-data config (an Array of Strings) into a
42+
# String that can be used as the value for the clear-site-data header.
43+
#
44+
# types - An Array of String of types of data to clear.
45+
#
46+
# Returns a String of quoted values that are comma separated.
47+
def self.make_header_value(types)
48+
types.map { |t| %("#{t}") }.join(", ")
5149
end
5250
end
5351
end

lib/secure_headers/headers/content_security_policy.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def build_sandbox_list_directive(directive)
7979
end
8080

8181
# A maximally strict sandbox policy is just the `sandbox` directive,
82-
# whith no configuraiton values.
82+
# with no configuration values.
8383
if max_strict_policy
8484
symbol_to_hyphen_case(directive)
8585
elsif sandbox_list && sandbox_list.any?
@@ -120,7 +120,7 @@ def build_source_list_directive(directive)
120120
end
121121

122122
# If a directive contains *, all other values are omitted.
123-
# If a directive contains 'none' but has other values, 'none' is ommitted.
123+
# If a directive contains 'none' but has other values, 'none' is omitted.
124124
# Schemes are stripped (see http://www.w3.org/TR/CSP2/#match-source-expression)
125125
def minify_source_list(directive, source_list)
126126
source_list = source_list.compact

lib/secure_headers/headers/cookie.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ module SecureHeaders
77
class CookiesConfigError < StandardError; end
88
class Cookie
99

10-
class << self
11-
def validate_config!(config)
12-
CookiesConfig.new(config).validate!
13-
end
10+
def self.validate_config!(config)
11+
CookiesConfig.new(config).validate!
1412
end
1513

1614
attr_reader :raw_cookie, :config

lib/secure_headers/headers/expect_certificate_transparency.rb

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,29 @@ class ExpectCertificateTransparency
99
REQUIRED_MAX_AGE_ERROR = "max-age is a required directive.".freeze
1010
INVALID_MAX_AGE_ERROR = "max-age must be a number.".freeze
1111

12-
class << self
13-
# Public: Generate a expect-ct header.
14-
#
15-
# Returns nil if not configured, returns header name and value if
16-
# configured.
17-
def make_header(config, use_agent = nil)
18-
return if config.nil? || config == OPT_OUT
12+
# Public: Generate a expect-ct header.
13+
#
14+
# Returns nil if not configured, returns header name and value if
15+
# configured.
16+
def self.make_header(config, use_agent = nil)
17+
return if config.nil? || config == OPT_OUT
1918

20-
header = new(config)
21-
[HEADER_NAME, header.value]
22-
end
19+
header = new(config)
20+
[HEADER_NAME, header.value]
21+
end
2322

24-
def validate_config!(config)
25-
return if config.nil? || config == OPT_OUT
26-
raise ExpectCertificateTransparencyConfigError.new(INVALID_CONFIGURATION_ERROR) unless config.is_a? Hash
23+
def self.validate_config!(config)
24+
return if config.nil? || config == OPT_OUT
25+
raise ExpectCertificateTransparencyConfigError.new(INVALID_CONFIGURATION_ERROR) unless config.is_a? Hash
2726

28-
unless [true, false, nil].include?(config[:enforce])
29-
raise ExpectCertificateTransparencyConfigError.new(INVALID_ENFORCE_VALUE_ERROR)
30-
end
27+
unless [true, false, nil].include?(config[:enforce])
28+
raise ExpectCertificateTransparencyConfigError.new(INVALID_ENFORCE_VALUE_ERROR)
29+
end
3130

32-
if !config[:max_age]
33-
raise ExpectCertificateTransparencyConfigError.new(REQUIRED_MAX_AGE_ERROR)
34-
elsif config[:max_age].to_s !~ /\A\d+\z/
35-
raise ExpectCertificateTransparencyConfigError.new(INVALID_MAX_AGE_ERROR)
36-
end
31+
if !config[:max_age]
32+
raise ExpectCertificateTransparencyConfigError.new(REQUIRED_MAX_AGE_ERROR)
33+
elsif config[:max_age].to_s !~ /\A\d+\z/
34+
raise ExpectCertificateTransparencyConfigError.new(INVALID_MAX_AGE_ERROR)
3735
end
3836
end
3937

0 commit comments

Comments
 (0)