Skip to content

Instantly share code, notes, and snippets.

@EduardoAC
Created October 27, 2025 18:35
Show Gist options
  • Select an option

  • Save EduardoAC/0411858aa6cbbc180c3ab01926152305 to your computer and use it in GitHub Desktop.

Select an option

Save EduardoAC/0411858aa6cbbc180c3ab01926152305 to your computer and use it in GitHub Desktop.
Cloud Function - CloudFront Cache poisoning prevention
function handler(event) {
var request = event.request;
var allowed = ["accept", "accept-encoding", "if-none-match", "if-modified-since", "user-agent", "range"];
var sanitized = {};
for (var h in request.headers) {
if (allowed.indexOf(h) !== -1) sanitized[h] = request.headers[h];
}
request.headers = sanitized;
request.uri = request.uri.replace(/\/+/g, "/");
return request;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment