-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathws-lambda-at-edge-add-security-headers.js
44 lines (36 loc) · 1.61 KB
/
ws-lambda-at-edge-add-security-headers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
exports.handler = async (event) => {
console.log('Event: ', JSON.stringify(event, null, 2));
const response = event.Records[0].cf.response;
/* Add HTTP Strict Transport Security to enforce HTTPS
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
*
* Strict-Transport-Security: max-age=31536000; includeSubDomains
*/
response.headers['strict-transport-security'] = [{ value: 'max-age=31536000; includeSubDomains' }];
/* Add Content-Security-Policy header to mitigate XSS.
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
*
* Content-Security-Policy: default-src https: 'self'
*/
response.headers['content-security-policy'] = [{ value: "default-src 'self'" }];
/* Add browser side XSS protection (for older browsers without CSP)
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
*
* X-XSS-Protection: 1; mode=block
*/
response.headers['x-xss-protection'] = [{ value: '1; mode=block' }];
/* Add MIME-type sniffing protection (also helps with XSS)
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
*
* X-Content-Type-Options: nosniff
*/
response.headers['x-content-type-options'] = [{ value: 'nosniff' }];
/* Add X-Frame-Options to disable framing and mitigate clickjacking
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
*
* X-Frame-Options: DENY
*/
response.headers['x-frame-options'] = [{ value: 'DENY' }];
return response;
};