Created
April 6, 2018 23:20
-
-
Save demsey2/c957cb6bcce39efad564ca40a266d84f to your computer and use it in GitHub Desktop.
CloudFront Lambda security headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://blog.crashtest-security.com/lambda-edge-to-configure-http-security-headers-for-cloudfront-34a44775061d | |
'use strict'; | |
exports.handler = (event, context, callback) => { | |
const response = event.Records[0].cf.response; | |
const headers = response.headers; | |
// Add security headers | |
const securityHeaders = [ | |
[{ | |
'value': 'max-age=31536000', | |
'key': 'Strict-Transport-Security' | |
}], | |
[{ | |
'value': 'deny', | |
'key': 'X-Frame-Options' | |
}], | |
[{ | |
'value': '1; mode=block', | |
'key': 'X-XSS-Protection' | |
}], | |
[{ | |
'value': 'nosniff', | |
'key': 'X-Content-Type-Options' | |
}], | |
[{ | |
'value': 'strict-origin-when-cross-origin', | |
'key': 'Referrer-Policy' | |
}] | |
]; | |
// Add all headers of the array to the response object in the correct format | |
for(let header of securityHeaders) { | |
headers[header[0].key.toLowerCase()] = header; | |
} | |
callback(null, response); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment