Forked from demsey2/gist:c957cb6bcce39efad564ca40a266d84f
Created
August 28, 2018 23:01
-
-
Save jonathanhle/ef6cd8e01901c8c355c04dde9c33e4b8 to your computer and use it in GitHub Desktop.
CloudFront Lambda security headers
This file contains hidden or 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