Skip to content

How to forward JA3 and JA4 headers to a cloudfront origin which is a lambda function URL

0

When using a lambda function URL as a cloudfront origin, the "Host" header from the client request must be dropped, so that cloudfront can add the lambda url as as a host header. Otherwise the lambda function url invocation does not work. This is achieved by using an origin request policy which drops the Host header, e.g. the AllViewerExceptHostHeader managed policy. However, while this policy does forward "Cloudfront-Viewer-*" headers, it does not forward the "CloudFront-Viewer-JA3-Fingerprint" and "CloudFront-Viewer-JA4-Fingerprint" headers. The only way (it appears) to include those headers is to add them to an origin request policy which allowlists them. But doing this prevents the removal of the Host headers. Basically, the problem is that origin request policies can either add headers or remove headers, but they cannot both add and remove headers.

Also, it is not possible to add the JA3 and JA4 headers to a cache policy.

For these TLS-related headers, you can add them to a origin request policy, but not in a cache policy.

asked a year ago627 views

1 Answer
0

To forward JA3 and JA4 fingerprint headers to a Lambda function URL origin while ensuring the Host header is properly handled, you'll need to create a custom origin request policy. Here's how to approach this:

  1. Create a custom origin request policy that:
  • Includes specific headers you want to forward (including CloudFront-Viewer-JA3-Fingerprint and CloudFront-Viewer-JA4-Fingerprint)
  • Does NOT include the Host header in the list of headers to forward

When you create a custom origin request policy and specify only certain headers to forward (without including the Host header), CloudFront will:

  • Forward only the headers you've specified
  • Not forward the Host header from the viewer request
  • Automatically set the Host header to the origin domain name (your Lambda function URL)

This approach allows you to:

  • Get the JA3 and JA4 fingerprint headers at your Lambda function
  • Ensure the Host header is set correctly for the Lambda function URL to work properly

Note that the JA3 and JA4 fingerprints are derived from the SSL/TLS Client Hello packet and are only present for HTTPS requests. These TLS-related headers can only be added to an origin request policy, not a cache policy.
Sources
Add CloudFront request headers - Amazon CloudFront
Configure Host header forwarding - AWS Elemental MediaTailor
Enhance your Security Posture and Reduce False Positives using Client JA3 Fingerprint and HTTP Header Order | Networking & Content Delivery

answered a year ago

  • That does indeed answer the original question. However, I realize now I should have been clearer on what I want: I also want all of the headers from the client request to be included, e.g. Accept, Accept-Encoding, etc, etc. I can't allowlist every single header that can exist in HTTP.

  • Hi Alan,

    I’ve been working on this exact scenario over the past few weeks and managed to solve it by combining a custom Origin Request Policy with a Lambda@Edge function.

    The core issue is that when you enable a policy to forward all headers (including the original Host header) to a CloudFront origin like a Lambda Function URL or an S3 Bucket, the origin rejects the request because the Host header doesn't match its own domain.

    Here is the step-by-step solution I implemented:

    1. Origin Request Policy Create a custom policy to forward the following:
    • All Viewer Headers (including the original Host).
    • Specific headers: CloudFront-Viewer-JA3-Fingerprint and CloudFront-Viewer-JA4-Fingerprint.
    1. Lambda@Edge (Origin Request Trigger) To fix the Host mismatch dynamically without hardcoding values for every behavior, use the following code on the Origin Request trigger.

    Why this works: The Lambda@Edge function intercepts the request after CloudFront has applied the origin request policy but before it reaches the origin. By swapping the viewer's Host for the origin's domainName, the origin (Lambda URL/S3/Custom Origin) accepts the request, yet your application still has access to the original JA3/JA4 fingerprints forwarded by CloudFront.

    I hope this helps anyone facing the same challenge!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.