Proxy Icons Are Not Firewalls

Putting a proxied DNS record in front of CloudFront and S3 handles volumetric L3/L7 noise well, yet in default configurations anyone who learns the underlying *.cloudfront.net domain can talk to the distribution directly, skipping edge WAF rules and rate limits completely.

Filtering CloudFront solely by Cloudflare's published IPv4 and IPv6 ranges closes direct client probes, but leaves a subtler second path open: multi-tenant CDN spoofing. Because edge proxies share egress IP pools across customer zones, another user can point a CNAME in their own account at your *.cloudfront.net hostname. Their traffic arrives from genuine proxy edge IPs while bypassing every firewall rule on your zone.

Pairing Peer-IP Sets with an Edge-Injected Secret

Closing both paths takes three independent checks before an object is ever read from storage:

LayerMechanismWhat It Stops
Edge ProxyFull (Strict) TLS, Min TLS 1.3, HSTS, WAF, Rate Limiting, Late Transform Rule injecting X-Origin-VerifyProtocol downgrade, scanner noise, burst scraping
CloudFront + WAFv2Default BLOCK; Allow requires (Peer IP ∈ Cloudflare IPSets) AND (X-Origin-Verify == secret) + TLSv1.3_2025Direct *.cloudfront.net access and cross-tenant proxy spoofing
Private S3 + KMSBlockPublicAccess, BucketOwnerEnforced, SigV4 OAC (AWS:SourceArn), rotated CMKDirect bucket reads, ACL drift, unencrypted storage

When matching the IP sets in AWS WAFv2, inspect the socket peer IP rather than X-Forwarded-For—any direct caller can forge a forwarded header, whereas they cannot spoof a TCP handshake from an edge CIDR:

hcl
statement {
  and_statement {
    statement {
      or_statement {
        statement {
          ip_set_reference_statement { arn = aws_wafv2_ip_set.cloudflare_ipv4.arn }
        }
        statement {
          ip_set_reference_statement { arn = aws_wafv2_ip_set.cloudflare_ipv6.arn }
        }
      }
    }
    statement {
      byte_match_statement {
        positional_constraint = "EXACTLY"
        search_string         = var.origin_verify_secret
        field_to_match {
          single_header { name = "x-origin-verify" }
        }
        text_transformation {
          priority = 0
          type     = "NONE"
        }
      }
    }
  }
}

Redacting the Shared Header in WAF Logs

One detail worth catching early: if WAFv2 access logging is enabled, every sampled request writes its headers into CloudWatch Logs unless explicitly scrubbed. Redacting x-origin-verify in the logging configuration keeps the shared secret out of log streams:

hcl
resource "aws_wafv2_web_acl_logging_configuration" "origin_lockdown" {
  log_destination_configs = [aws_cloudwatch_log_group.waf.arn]
  resource_arn            = aws_wafv2_web_acl.origin_lockdown.arn

  redacted_fields {
    single_header { name = "x-origin-verify" }
  }
}