Skip to content

Commit

Permalink
Delete Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Ramplin committed Dec 19, 2024
1 parent 795dbae commit 006a602
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cdn/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ locals {
locations = coalesce(var.config.cdn_geo_locations, [])
}

headers_to_remove = [ "X-Cache", "Via", "X-Amz-Cf-Pop", "X-Amz-Cf-Id", "Server" ]

# By default logging is off on all distros.
logging_config = coalesce(var.config.enable_logging, false) ? { bucket = local.logging_bucket } : {}

Expand Down
16 changes: 16 additions & 0 deletions cdn/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ resource "aws_cloudfront_distribution" "standard" {
# If the variable paths/{domain}/default/[cache/request] are set.
cache_policy_id = try(data.aws_cloudfront_cache_policy.policy-name[var.config.paths[each.key].default.cache].id, "")
origin_request_policy_id = try(data.aws_cloudfront_origin_request_policy.request-policy-name[var.config.paths[each.key].default.request].id, "")
response_headers_policy_id = aws_cloudfront_response_headers_policy.insecure_headers.id
}

# If path based routing is set in platform-config.yml then this is run per path, you will always attach a policy to a path.
Expand Down Expand Up @@ -242,6 +243,21 @@ resource "aws_cloudfront_cache_policy" "cache_policy" {
}
}

resource "aws_cloudfront_response_headers_policy" "insecure_headers" {
provider = aws.domain-cdn
name = "delete-headers-exposing-platform-details-${var.application}-${var.environment}"

remove_headers_config {
dynamic "items" {
for_each = local.cdn_defaults.headers_to_remove
content {
header = items.value
}
}
}
}


# We do not cache origin requests, so leaving all config as default.
resource "aws_cloudfront_origin_request_policy" "origin_request_policy" {
provider = aws.domain-cdn
Expand Down

0 comments on commit 006a602

Please sign in to comment.