Skip to content

Instantly share code, notes, and snippets.

@DerPauli
Created April 11, 2020 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DerPauli/ea941697efcbd9638884b7a8cbbfd60d to your computer and use it in GitHub Desktop.
Save DerPauli/ea941697efcbd9638884b7a8cbbfd60d to your computer and use it in GitHub Desktop.
CloudFront Lambda@Edge function to change response headers
'use strict';
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
const headers = response.headers;
// Server header to conceil technology
headers['server'] = [{
key: 'Server',
value: ""
}];
headers['strict-transport-security'] = [{
key: 'Strict-Transport-Security',
value: "max-age=31536000; includeSubdomains; preload"
}];
headers['content-security-policy'] = [{
key: 'Content-Security-Policy',
value: "default-src 'self'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'; font-src 'self'
}];
headers['x-content-type-options'] = [{
key: 'X-Content-Type-Options',
value: "nosniff"
}];
headers['x-frame-options'] = [{
key: 'X-Frame-Options',
value: "DENY"
}];
headers['x-xss-protection'] = [{
key: 'X-XSS-Protection',
value: "1; mode=block"
}];
headers['referrer-policy'] = [{
key: 'Referrer-Policy',
value: "same-origin"
}];
headers['feature-policy'] = [{
key: 'Feature-Policy',
value: "autoplay 'none'; camera 'none'; fullscreen 'self'; geolocation 'none'; microphone 'none'; payment 'none'"
}];
callback(null, response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment