Skip to content

Commit b208b8a

Browse files
committed
remove hpkp
Fixes #368
1 parent 9059753 commit b208b8a

File tree

8 files changed

+3
-200
lines changed

8 files changed

+3
-200
lines changed

lib/secure_headers.rb

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22
require "secure_headers/hash_helper"
33
require "secure_headers/headers/cookie"
4-
require "secure_headers/headers/public_key_pins"
54
require "secure_headers/headers/content_security_policy"
65
require "secure_headers/headers/x_frame_options"
76
require "secure_headers/headers/strict_transport_security"
@@ -18,8 +17,7 @@
1817
require "singleton"
1918
require "secure_headers/configuration"
2019

21-
# All headers (except for hpkp) have a default value. Provide SecureHeaders::OPT_OUT
22-
# or ":optout_of_protection" as a config value to disable a given header
20+
# Provide SecureHeaders::OPT_OUT as a config value to disable a given header
2321
module SecureHeaders
2422
class NoOpHeaderConfig
2523
include Singleton
@@ -51,10 +49,6 @@ def opt_out?
5149
HTTPS = "https".freeze
5250
CSP = ContentSecurityPolicy
5351

54-
# Headers set on http requests (excludes STS and HPKP)
55-
HTTPS_HEADER_CLASSES =
56-
[StrictTransportSecurity, PublicKeyPins].freeze
57-
5852
class << self
5953
# Public: override a given set of directives for the current request. If a
6054
# value already exists for a given directive, it will be overridden.
@@ -138,7 +132,7 @@ def opt_out_of_all_protection(request)
138132
# Public: Builds the hash of headers that should be applied base on the
139133
# request.
140134
#
141-
# StrictTransportSecurity and PublicKeyPins are not applied to http requests.
135+
# StrictTransportSecurity is not applied to http requests.
142136
# See #config_for to determine which config is used for a given request.
143137
#
144138
# Returns a hash of header names => header values. The value
@@ -151,9 +145,7 @@ def header_hash_for(request)
151145
headers = config.generate_headers
152146

153147
if request.scheme != HTTPS
154-
HTTPS_HEADER_CLASSES.each do |klass|
155-
headers.delete(klass::HEADER_NAME)
156-
end
148+
headers.delete(StrictTransportSecurity::HEADER_NAME)
157149
end
158150
headers
159151
end

lib/secure_headers/configuration.rb

-9
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ def deep_copy_if_hash(value)
115115
expect_certificate_transparency: ExpectCertificateTransparency,
116116
csp: ContentSecurityPolicy,
117117
csp_report_only: ContentSecurityPolicy,
118-
hpkp: PublicKeyPins,
119118
cookies: Cookie,
120119
}.freeze
121120

@@ -144,7 +143,6 @@ def initialize(&block)
144143
@clear_site_data = nil
145144
@csp = nil
146145
@csp_report_only = nil
147-
@hpkp = nil
148146
@hsts = nil
149147
@x_content_type_options = nil
150148
@x_download_options = nil
@@ -153,7 +151,6 @@ def initialize(&block)
153151
@x_xss_protection = nil
154152
@expect_certificate_transparency = nil
155153

156-
self.hpkp = OPT_OUT
157154
self.referrer_policy = OPT_OUT
158155
self.csp = ContentSecurityPolicyConfig.new(ContentSecurityPolicyConfig::DEFAULT)
159156
self.csp_report_only = OPT_OUT
@@ -178,7 +175,6 @@ def dup
178175
copy.clear_site_data = @clear_site_data
179176
copy.expect_certificate_transparency = @expect_certificate_transparency
180177
copy.referrer_policy = @referrer_policy
181-
copy.hpkp = @hpkp
182178
copy
183179
end
184180

@@ -263,10 +259,5 @@ def csp_report_only=(new_csp)
263259
raise ArgumentError, "Must provide either an existing CSP config or a CSP config hash"
264260
end
265261
end
266-
267-
def hpkp_report_host
268-
return nil unless @hpkp && hpkp != OPT_OUT && @hpkp[:report_uri]
269-
URI.parse(@hpkp[:report_uri]).host
270-
end
271262
end
272263
end

lib/secure_headers/headers/public_key_pins.rb

-81
This file was deleted.

lib/secure_headers/middleware.rb

-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22
module SecureHeaders
33
class Middleware
4-
HPKP_SAME_HOST_WARNING = "[WARNING] HPKP report host should not be the same as the request host. See https://github.com/twitter/secureheaders/issues/166"
5-
64
def initialize(app)
75
@app = app
86
end
@@ -13,10 +11,6 @@ def call(env)
1311
status, headers, response = @app.call(env)
1412

1513
config = SecureHeaders.config_for(req)
16-
if config.hpkp_report_host == req.host
17-
Kernel.warn(HPKP_SAME_HOST_WARNING)
18-
end
19-
2014
flag_cookies!(headers, override_secure(env, config.cookies)) unless config.cookies == OPT_OUT
2115
headers.merge!(SecureHeaders.header_hash_for(req))
2216
[status, headers, response]

spec/lib/secure_headers/headers/public_key_pins_spec.rb

-38
This file was deleted.

spec/lib/secure_headers/middleware_spec.rb

-19
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,6 @@ module SecureHeaders
1414
Configuration.default
1515
end
1616

17-
it "warns if the hpkp report-uri host is the same as the current host" do
18-
report_host = "report-uri.io"
19-
reset_config
20-
Configuration.default do |config|
21-
config.hpkp = {
22-
max_age: 10000000,
23-
pins: [
24-
{sha256: "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c"},
25-
{sha256: "73a2c64f9545172c1195efb6616ca5f7afd1df6f245407cafb90de3998a1c97f"}
26-
],
27-
report_uri: "https://#{report_host}/example-hpkp"
28-
}
29-
end
30-
31-
expect(Kernel).to receive(:warn).with(Middleware::HPKP_SAME_HOST_WARNING)
32-
33-
middleware.call(Rack::MockRequest.env_for("https://#{report_host}", {}))
34-
end
35-
3617
it "sets the headers" do
3718
_, env = middleware.call(Rack::MockRequest.env_for("https://looocalhost", {}))
3819
expect_default_values(env)

spec/lib/secure_headers_spec.rb

-35
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,6 @@ module SecureHeaders
9090
Configuration.default do |config|
9191
config.csp = { default_src: ["example.com"], script_src: %w('self') }
9292
config.csp_report_only = config.csp
93-
config.hpkp = {
94-
report_only: false,
95-
max_age: 10000000,
96-
include_subdomains: true,
97-
report_uri: "https://report-uri.io/example-hpkp",
98-
pins: [
99-
{sha256: "abc"},
100-
{sha256: "123"}
101-
]
102-
}
10393
end
10494
SecureHeaders.opt_out_of_all_protection(request)
10595
hash = SecureHeaders.header_hash_for(request)
@@ -141,23 +131,6 @@ module SecureHeaders
141131
expect(SecureHeaders.header_hash_for(plaintext_request)[StrictTransportSecurity::HEADER_NAME]).to be_nil
142132
end
143133

144-
it "does not set the HPKP header if request is over HTTP" do
145-
plaintext_request = Rack::Request.new({})
146-
Configuration.default do |config|
147-
config.hpkp = {
148-
max_age: 1_000_000,
149-
include_subdomains: true,
150-
report_uri: "//example.com/uri-directive",
151-
pins: [
152-
{ sha256: "abc" },
153-
{ sha256: "123" }
154-
]
155-
}
156-
end
157-
158-
expect(SecureHeaders.header_hash_for(plaintext_request)[PublicKeyPins::HEADER_NAME]).to be_nil
159-
end
160-
161134
context "content security policy" do
162135
let(:chrome_request) {
163136
Rack::Request.new(request.env.merge("HTTP_USER_AGENT" => USER_AGENTS[:chrome]))
@@ -531,14 +504,6 @@ module SecureHeaders
531504
end.to raise_error(ReferrerPolicyConfigError)
532505
end
533506

534-
it "validates your hpkp config upon configuration" do
535-
expect do
536-
Configuration.default do |config|
537-
config.hpkp = "lol"
538-
end
539-
end.to raise_error(PublicKeyPinsConfigError)
540-
end
541-
542507
it "validates your cookies config upon configuration" do
543508
expect do
544509
Configuration.default do |config|

spec/spec_helper.rb

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def expect_default_values(hash)
3737
expect(hash[SecureHeaders::ExpectCertificateTransparency::HEADER_NAME]).to be_nil
3838
expect(hash[SecureHeaders::ClearSiteData::HEADER_NAME]).to be_nil
3939
expect(hash[SecureHeaders::ExpectCertificateTransparency::HEADER_NAME]).to be_nil
40-
expect(hash[SecureHeaders::PublicKeyPins::HEADER_NAME]).to be_nil
4140
end
4241

4342
module SecureHeaders

0 commit comments

Comments
 (0)