@middy/http-security-headers 2.5.5 → 2.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +80 -86
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
normalizeHttpResponse
|
|
5
|
-
} = require('@middy/util'); // Code and Defaults heavily based off https://helmetjs.github.io/
|
|
1
|
+
const { normalizeHttpResponse } = require('@middy/util')
|
|
6
2
|
|
|
3
|
+
// Code and Defaults heavily based off https://helmetjs.github.io/
|
|
7
4
|
|
|
8
5
|
const defaults = {
|
|
9
6
|
// contentDisposition: {
|
|
@@ -36,7 +33,6 @@ const defaults = {
|
|
|
36
33
|
},
|
|
37
34
|
permittedCrossDomainPolicies: {
|
|
38
35
|
policy: 'none' // none, master-only, by-content-type, by-ftp-filename, all
|
|
39
|
-
|
|
40
36
|
},
|
|
41
37
|
referrerPolicy: {
|
|
42
38
|
policy: 'no-referrer'
|
|
@@ -44,128 +40,126 @@ const defaults = {
|
|
|
44
40
|
xssFilter: {
|
|
45
41
|
reportUri: ''
|
|
46
42
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const helmet = {}
|
|
46
|
+
const helmetHtmlOnly = {}
|
|
47
|
+
|
|
48
|
+
// OWASP ASVS 14.4.2
|
|
50
49
|
// API Gateway strips out this header :(
|
|
51
50
|
// helmet.content = (headers, config) => {
|
|
52
51
|
// const filename = config.filename ?? `api.${headers?.['Content-Type'].split(/[/;]/)[1] ?? 'json'}`
|
|
53
52
|
// headers['Content-Disposition'] = `attachment; filename="${filename}"`
|
|
54
53
|
// }
|
|
54
|
+
|
|
55
55
|
// contentSecurityPolicy - N/A - no HTML
|
|
56
56
|
// featurePolicy - N/A - no HTML
|
|
57
|
+
|
|
57
58
|
// crossdomain - N/A - For Adobe products
|
|
58
|
-
// https://github.com/helmetjs/dns-Prefetch-control
|
|
59
59
|
|
|
60
|
+
// https://github.com/helmetjs/dns-Prefetch-control
|
|
60
61
|
helmet.dnsPrefetchControl = (headers, config) => {
|
|
61
|
-
headers['X-DNS-Prefetch-Control'] = config.allow ? 'on' : 'off'
|
|
62
|
-
return headers
|
|
63
|
-
}
|
|
64
|
-
// https://github.com/helmetjs/frameguard
|
|
62
|
+
headers['X-DNS-Prefetch-Control'] = config.allow ? 'on' : 'off'
|
|
63
|
+
return headers
|
|
64
|
+
}
|
|
65
65
|
|
|
66
|
+
// expectCt - in-progress spec
|
|
66
67
|
|
|
68
|
+
// https://github.com/helmetjs/frameguard
|
|
67
69
|
helmetHtmlOnly.frameguard = (headers, config) => {
|
|
68
|
-
headers['X-Frame-Options'] = config.action.toUpperCase()
|
|
69
|
-
return headers
|
|
70
|
-
}
|
|
71
|
-
|
|
70
|
+
headers['X-Frame-Options'] = config.action.toUpperCase()
|
|
71
|
+
return headers
|
|
72
|
+
}
|
|
72
73
|
|
|
74
|
+
// https://github.com/helmetjs/hide-powered-by
|
|
73
75
|
helmet.hidePoweredBy = (headers, config) => {
|
|
74
76
|
if (config.setTo) {
|
|
75
|
-
headers['X-Powered-By'] = config.setTo
|
|
77
|
+
headers['X-Powered-By'] = config.setTo
|
|
76
78
|
} else {
|
|
77
|
-
Reflect.deleteProperty(headers, 'Server')
|
|
78
|
-
Reflect.deleteProperty(headers, 'X-Powered-By')
|
|
79
|
+
Reflect.deleteProperty(headers, 'Server')
|
|
80
|
+
Reflect.deleteProperty(headers, 'X-Powered-By')
|
|
79
81
|
}
|
|
82
|
+
return headers
|
|
83
|
+
}
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
}; // hpkp - deprecated
|
|
83
|
-
// https://github.com/helmetjs/hsts
|
|
84
|
-
|
|
85
|
+
// hpkp - deprecated
|
|
85
86
|
|
|
87
|
+
// https://github.com/helmetjs/hsts
|
|
86
88
|
helmet.hsts = (headers, config) => {
|
|
87
|
-
let header = 'max-age=' + Math.round(config.maxAge)
|
|
88
|
-
|
|
89
|
+
let header = 'max-age=' + Math.round(config.maxAge)
|
|
89
90
|
if (config.includeSubDomains) {
|
|
90
|
-
header += '; includeSubDomains'
|
|
91
|
+
header += '; includeSubDomains'
|
|
91
92
|
}
|
|
92
|
-
|
|
93
93
|
if (config.preload) {
|
|
94
|
-
header += '; preload'
|
|
94
|
+
header += '; preload'
|
|
95
95
|
}
|
|
96
|
+
headers['Strict-Transport-Security'] = header
|
|
97
|
+
return headers
|
|
98
|
+
}
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
return headers;
|
|
99
|
-
}; // https://github.com/helmetjs/ienoopen
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
// https://github.com/helmetjs/ienoopen
|
|
102
101
|
helmet.ieNoOpen = (headers, config) => {
|
|
103
|
-
headers['X-Download-Options'] = config.action
|
|
104
|
-
return headers
|
|
105
|
-
}
|
|
106
|
-
// https://github.com/helmetjs/dont-sniff-mimetype
|
|
102
|
+
headers['X-Download-Options'] = config.action
|
|
103
|
+
return headers
|
|
104
|
+
}
|
|
107
105
|
|
|
106
|
+
// noCache - N/A - separate middleware
|
|
108
107
|
|
|
108
|
+
// https://github.com/helmetjs/dont-sniff-mimetype
|
|
109
109
|
helmet.noSniff = (headers, config) => {
|
|
110
|
-
headers['X-Content-Type-Options'] = config.action
|
|
111
|
-
return headers
|
|
112
|
-
}
|
|
113
|
-
|
|
110
|
+
headers['X-Content-Type-Options'] = config.action
|
|
111
|
+
return headers
|
|
112
|
+
}
|
|
114
113
|
|
|
114
|
+
// https://github.com/helmetjs/referrer-policy
|
|
115
115
|
helmet.referrerPolicy = (headers, config) => {
|
|
116
|
-
headers['Referrer-Policy'] = config.policy
|
|
117
|
-
return headers
|
|
118
|
-
}
|
|
119
|
-
|
|
116
|
+
headers['Referrer-Policy'] = config.policy
|
|
117
|
+
return headers
|
|
118
|
+
}
|
|
120
119
|
|
|
120
|
+
// https://github.com/helmetjs/crossdomain
|
|
121
121
|
helmet.permittedCrossDomainPolicies = (headers, config) => {
|
|
122
|
-
headers['X-Permitted-Cross-Domain-Policies'] = config.policy
|
|
123
|
-
return headers
|
|
124
|
-
}
|
|
125
|
-
|
|
122
|
+
headers['X-Permitted-Cross-Domain-Policies'] = config.policy
|
|
123
|
+
return headers
|
|
124
|
+
}
|
|
126
125
|
|
|
126
|
+
// https://github.com/helmetjs/x-xss-protection
|
|
127
127
|
helmetHtmlOnly.xssFilter = (headers, config) => {
|
|
128
|
-
let header = '1; mode=block'
|
|
129
|
-
|
|
128
|
+
let header = '1; mode=block'
|
|
130
129
|
if (config.reportUri) {
|
|
131
|
-
header += '; report=' + config.reportUri
|
|
130
|
+
header += '; report=' + config.reportUri
|
|
132
131
|
}
|
|
133
|
-
|
|
134
|
-
headers
|
|
135
|
-
|
|
136
|
-
};
|
|
132
|
+
headers['X-XSS-Protection'] = header
|
|
133
|
+
return headers
|
|
134
|
+
}
|
|
137
135
|
|
|
138
136
|
const httpSecurityHeadersMiddleware = (opts = {}) => {
|
|
139
|
-
const options = { ...defaults,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
...options[key]
|
|
158
|
-
};
|
|
159
|
-
request.response.headers = helmetHtmlOnly[key](request.response.headers, config);
|
|
160
|
-
});
|
|
137
|
+
const options = { ...defaults, ...opts }
|
|
138
|
+
|
|
139
|
+
const httpSecurityHeadersMiddlewareAfter = async (request) => {
|
|
140
|
+
request.response = normalizeHttpResponse(request.response)
|
|
141
|
+
|
|
142
|
+
Object.keys(helmet).forEach((key) => {
|
|
143
|
+
const config = { ...defaults[key], ...options[key] }
|
|
144
|
+
request.response.headers = helmet[key](request.response.headers, config)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
if (request.response.headers?.['Content-Type']?.includes('text/html')) {
|
|
148
|
+
Object.keys(helmetHtmlOnly).forEach((key) => {
|
|
149
|
+
const config = { ...defaults[key], ...options[key] }
|
|
150
|
+
request.response.headers = helmetHtmlOnly[key](
|
|
151
|
+
request.response.headers,
|
|
152
|
+
config
|
|
153
|
+
)
|
|
154
|
+
})
|
|
161
155
|
}
|
|
162
|
-
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const httpSecurityHeadersMiddlewareOnError = httpSecurityHeadersMiddlewareAfter
|
|
163
159
|
|
|
164
|
-
const httpSecurityHeadersMiddlewareOnError = httpSecurityHeadersMiddlewareAfter;
|
|
165
160
|
return {
|
|
166
161
|
after: httpSecurityHeadersMiddlewareAfter,
|
|
167
162
|
onError: httpSecurityHeadersMiddlewareOnError
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
module.exports = httpSecurityHeadersMiddleware;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
module.exports = httpSecurityHeadersMiddleware
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-security-headers",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.6",
|
|
4
4
|
"description": "Applies best practice security headers to responses. It's a simplified port of HelmetJS",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"engines": {
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"url": "https://github.com/middyjs/middy/issues"
|
|
49
49
|
},
|
|
50
50
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "0c789f55b4adf691f977b0d9904d1a805bb3bb2b",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@middy/util": "^2.5.
|
|
53
|
+
"@middy/util": "^2.5.6"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@middy/core": "^2.5.
|
|
56
|
+
"@middy/core": "^2.5.6"
|
|
57
57
|
}
|
|
58
58
|
}
|