Skip to content

Commit 58f2e47

Browse files
authored
Removing HPKP and Expect-CT (#92)
1 parent 1b1c685 commit 58f2e47

File tree

3 files changed

+1
-150
lines changed

3 files changed

+1
-150
lines changed

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Content-Security-Policy: script-src 'nonce-a2ZobGFoZg=='
5353
~~~
5454

5555
### Set the `IsDevelopment` option to `true` when developing!
56-
When `IsDevelopment` is true, the AllowedHosts, SSLRedirect, STS header, and HPKP header will not be in effect. This allows you to work in development/test mode and not have any annoying redirects to HTTPS (ie. development can happen on HTTP), or block `localhost` has a bad host.
56+
When `IsDevelopment` is true, the AllowedHosts, SSLRedirect, and STS header will not be in effect. This allows you to work in development/test mode and not have any annoying redirects to HTTPS (ie. development can happen on HTTP), or block `localhost` has a bad host.
5757

5858
### Available options
5959
Secure comes with a variety of configuration options (Note: these are not the default option values. See the defaults below.):
@@ -80,12 +80,10 @@ s := secure.New(secure.Options{
8080
BrowserXssFilter: true, // If BrowserXssFilter is true, adds the X-XSS-Protection header with the value `1; mode=block`. Default is false.
8181
CustomBrowserXssValue: "1; report=https://example.com/xss-report", // CustomBrowserXssValue allows the X-XSS-Protection header value to be set with a custom value. This overrides the BrowserXssFilter option. Default is "".
8282
ContentSecurityPolicy: "default-src 'self'", // ContentSecurityPolicy allows the Content-Security-Policy header value to be set with a custom value. Default is "". Passing a template string will replace `$NONCE` with a dynamic nonce value of 16 bytes for each request which can be later retrieved using the Nonce function.
83-
PublicKey: `pin-sha256="base64+primary=="; pin-sha256="base64+backup=="; max-age=5184000; includeSubdomains; report-uri="https://www.example.com/hpkp-report"`, // Deprecated: This feature is no longer recommended. PublicKey implements HPKP to prevent MITM attacks with forged certificates. Default is "".
8483
ReferrerPolicy: "same-origin", // ReferrerPolicy allows the Referrer-Policy header with the value to be set with a custom value. Default is "".
8584
FeaturePolicy: "vibrate 'none';", // Deprecated: this header has been renamed to PermissionsPolicy. FeaturePolicy allows the Feature-Policy header with the value to be set with a custom value. Default is "".
8685
PermissionsPolicy: "fullscreen=(), geolocation=()", // PermissionsPolicy allows the Permissions-Policy header with the value to be set with a custom value. Default is "".
8786
CrossOriginOpenerPolicy: "same-origin", // CrossOriginOpenerPolicy allows the Cross-Origin-Opener-Policy header with the value to be set with a custom value. Default is "".
88-
ExpectCTHeader: `enforce, max-age=30, report-uri="https://www.example.com/ct-report"`,
8987

9088
IsDevelopment: true, // This will cause the AllowedHosts, SSLRedirect, and STSSeconds/STSIncludeSubdomains options to be ignored during development. When deploying to production, be sure to set this to false.
9189
})
@@ -123,7 +121,6 @@ l := secure.New(secure.Options{
123121
FeaturePolicy: "",
124122
PermissionsPolicy: "",
125123
CrossOriginOpenerPolicy: "",
126-
ExpectCTHeader: "",
127124
IsDevelopment: false,
128125
})
129126
~~~

secure.go

-16
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const (
2626
referrerPolicyHeader = "Referrer-Policy"
2727
featurePolicyHeader = "Feature-Policy"
2828
permissionsPolicyHeader = "Permissions-Policy"
29-
expectCTHeader = "Expect-CT"
3029
coopHeader = "Cross-Origin-Opener-Policy"
3130

3231
ctxDefaultSecureHeaderKey = secureCtxKey("SecureResponseHeader")
@@ -82,9 +81,6 @@ type Options struct {
8281
// Eg: script-src $NONCE -> script-src 'nonce-a2ZobGFoZg=='
8382
// CustomFrameOptionsValue allows the X-Frame-Options header value to be set with a custom value. This overrides the FrameDeny option. Default is "".
8483
CustomFrameOptionsValue string
85-
// PublicKey implements HPKP to prevent MITM attacks with forged certificates. Default is "".
86-
// Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible.
87-
PublicKey string
8884
// ReferrerPolicy allows sites to control when browsers will pass the Referer header to other sites. Default is "".
8985
ReferrerPolicy string
9086
// FeaturePolicy allows to selectively enable and disable use of various browser features and APIs. Default is "".
@@ -112,8 +108,6 @@ type Options struct {
112108
SSLProxyHeaders map[string]string
113109
// STSSeconds is the max-age of the Strict-Transport-Security header. Default is 0, which would NOT include the header.
114110
STSSeconds int64
115-
// ExpectCTHeader allows the Expect-CT header value to be set with a custom value. Default is "".
116-
ExpectCTHeader string
117111
// SecureContextKey allows a custom key to be specified for context storage.
118112
SecureContextKey string
119113
}
@@ -434,11 +428,6 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He
434428
responseHeader.Set(xssProtectionHeader, xssProtectionValue)
435429
}
436430

437-
// HPKP header.
438-
if len(s.opt.PublicKey) > 0 && ssl && !s.opt.IsDevelopment {
439-
responseHeader.Set(hpkpHeader, s.opt.PublicKey)
440-
}
441-
442431
// Content Security Policy header.
443432
if len(s.opt.ContentSecurityPolicy) > 0 {
444433
if s.opt.nonceEnabled {
@@ -477,11 +466,6 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He
477466
responseHeader.Set(coopHeader, s.opt.CrossOriginOpenerPolicy)
478467
}
479468

480-
// Expect-CT header.
481-
if len(s.opt.ExpectCTHeader) > 0 {
482-
responseHeader.Set(expectCTHeader, s.opt.ExpectCTHeader)
483-
}
484-
485469
return responseHeader, r, nil
486470
}
487471

secure_test.go

-130
Original file line numberDiff line numberDiff line change
@@ -969,121 +969,6 @@ func TestInlineSecureForRequestOnly(t *testing.T) {
969969
expect(t, res.Header().Get("X-Frame-Options"), "")
970970
}
971971

972-
// https://developer.mozilla.org/en-US/docs/Web/Security/Public_Key_Pinning
973-
const hpkp = `pin-sha256="cUPcTAZWKaASuYWhhneDttWpY3oBAkE3h2+soZS7sWs="; pin-sha256="M8HztCzM3elUxkcjR2S5P4hhyBNf6lHkmjAHKhpGPWE="; max-age=5184000; includeSubdomains; report-uri="https://www.example.net/hpkp-report"`
974-
975-
func TestHPKP(t *testing.T) {
976-
s := New(Options{
977-
PublicKey: hpkp,
978-
})
979-
980-
res := httptest.NewRecorder()
981-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
982-
req.URL.Scheme = "https"
983-
984-
s.Handler(myHandler).ServeHTTP(res, req)
985-
986-
expect(t, res.Code, http.StatusOK)
987-
expect(t, res.Header().Get("Public-Key-Pins"), hpkp)
988-
}
989-
990-
func TestHPKPForRequestOnly(t *testing.T) {
991-
s := New(Options{
992-
PublicKey: hpkp,
993-
})
994-
995-
res := httptest.NewRecorder()
996-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
997-
req.URL.Scheme = "https"
998-
999-
s.HandlerForRequestOnly(myHandler).ServeHTTP(res, req)
1000-
1001-
expect(t, res.Code, http.StatusOK)
1002-
expect(t, res.Header().Get("Public-Key-Pins"), "")
1003-
}
1004-
1005-
func TestHPKPNotSet(t *testing.T) {
1006-
s := New()
1007-
1008-
res := httptest.NewRecorder()
1009-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
1010-
1011-
s.Handler(myHandler).ServeHTTP(res, req)
1012-
1013-
expect(t, res.Code, http.StatusOK)
1014-
expect(t, res.Header().Get("Public-Key-Pins"), "")
1015-
}
1016-
1017-
func TestHPKPNotSetForRequestOnly(t *testing.T) {
1018-
s := New()
1019-
1020-
res := httptest.NewRecorder()
1021-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
1022-
1023-
s.HandlerForRequestOnly(myHandler).ServeHTTP(res, req)
1024-
1025-
expect(t, res.Code, http.StatusOK)
1026-
expect(t, res.Header().Get("Public-Key-Pins"), "")
1027-
}
1028-
1029-
func TestHPKPInDevMode(t *testing.T) {
1030-
s := New(Options{
1031-
PublicKey: hpkp,
1032-
IsDevelopment: true,
1033-
})
1034-
1035-
res := httptest.NewRecorder()
1036-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
1037-
1038-
s.Handler(myHandler).ServeHTTP(res, req)
1039-
1040-
expect(t, res.Code, http.StatusOK)
1041-
expect(t, res.Header().Get("Public-Key-Pins"), "")
1042-
}
1043-
1044-
func TestHPKPInDevModeForRequestOnly(t *testing.T) {
1045-
s := New(Options{
1046-
PublicKey: hpkp,
1047-
IsDevelopment: true,
1048-
})
1049-
1050-
res := httptest.NewRecorder()
1051-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
1052-
1053-
s.HandlerForRequestOnly(myHandler).ServeHTTP(res, req)
1054-
1055-
expect(t, res.Code, http.StatusOK)
1056-
expect(t, res.Header().Get("Public-Key-Pins"), "")
1057-
}
1058-
1059-
func TestHPKPNonSSL(t *testing.T) {
1060-
s := New(Options{
1061-
PublicKey: hpkp,
1062-
})
1063-
1064-
res := httptest.NewRecorder()
1065-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
1066-
1067-
s.Handler(myHandler).ServeHTTP(res, req)
1068-
1069-
expect(t, res.Code, http.StatusOK)
1070-
expect(t, res.Header().Get("Public-Key-Pins"), "")
1071-
}
1072-
1073-
func TestHPKPNonSSLForRequestOnly(t *testing.T) {
1074-
s := New(Options{
1075-
PublicKey: hpkp,
1076-
})
1077-
1078-
res := httptest.NewRecorder()
1079-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
1080-
1081-
s.HandlerForRequestOnly(myHandler).ServeHTTP(res, req)
1082-
1083-
expect(t, res.Code, http.StatusOK)
1084-
expect(t, res.Header().Get("Public-Key-Pins"), "")
1085-
}
1086-
1087972
func TestReferrer(t *testing.T) {
1088973
s := New(Options{
1089974
ReferrerPolicy: "same-origin",
@@ -1154,21 +1039,6 @@ func TestCrossOriginOpenerPolicy(t *testing.T) {
11541039
expect(t, res.Header().Get("Cross-Origin-Opener-Policy"), "same-origin")
11551040
}
11561041

1157-
func TestExpectCT(t *testing.T) {
1158-
s := New(Options{
1159-
ExpectCTHeader: `enforce, max-age=30, report-uri="https://www.example.com/ct-report"`,
1160-
})
1161-
1162-
res := httptest.NewRecorder()
1163-
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/foo", nil)
1164-
req.Host = "www.example.com"
1165-
1166-
s.Handler(myHandler).ServeHTTP(res, req)
1167-
1168-
expect(t, res.Code, http.StatusOK)
1169-
expect(t, res.Header().Get("Expect-CT"), `enforce, max-age=30, report-uri="https://www.example.com/ct-report"`)
1170-
}
1171-
11721042
func TestIsSSL(t *testing.T) {
11731043
s := New(Options{
11741044
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},

0 commit comments

Comments
 (0)