-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cloudfront: Failed to forward Authorization header from cloudfront to API Gateway #13408
Comments
@apoorvmote You can't pass See these references for more info: |
@njlynch I couldn't really find anywhere in docs that |
@njlynch And I found out there is limitation on how many headers you can whitelist (total of 10). AFAIK... none of this is captured anywhere in |
@robertd Thanks very much for quick reply. I though I had to wait many days before anyone will take a look at it. I would like help setting Cache Policy because its for API endpoint I have been using static Now to allow Headers I need to recreate the I was working on workaround. Instead of passing token through header I was going to pass it through body. Changing Is there any security concern by passing token via body? or I MUST pass token via header? |
This is actually reasonably straightforward. Simply create a new CachePolicy with 0s for all TTLs, and add the header policy. Then use this new cache policy with your distribution. const cachePolicy = new cloudfront.CachePolicy(stack, 'CachingDisabledButWithAuth', {
defaultTtl: Duration.minutes(0),
minTtl: Duration.minutes(0),
maxTtl: Duration.minutes(0),
headerBehavior: cloudfront.CacheHeaderBehavior.allowList('Authorization'),
}); |
|
Quick addition to @njlynch 's response. I had to set at least 1 of the TTL's to something in order to create the cache policy, so I set max TTL to 1 second: const cachePolicy = new cloudfront.CachePolicy(stack, 'CachingDisabledButWithAuth', {
defaultTtl: Duration.minutes(0),
minTtl: Duration.minutes(0),
maxTtl: Duration.minutes(1),
headerBehavior: cloudfront.CacheHeaderBehavior.allowList('Authorization'),
}); |
Seeing the same issue, and it happens if you try to create a stand-alone cache policy in the AWS Console. You get the annoying error: "The parameter HeaderBehavior is invalid for policy with caching disabled." However, if you manually modify caching on a CloudFront distribution, somehow AWS Console allows it. So "yes, we want caching disabled, and YES we want to pass an API Token, or other authorization header to the API Gateway!!" |
So I've spotted a nasty issue using @bblanke's solution. If you batch requests with the same path (different headers and/or different query params), CF/APIGW will (not always, but almost always, probably due to load balancing) give them all the same requestId (see, |
If the origin is API Gateway, then it is recommended to use
AllViewerExceptHostHeader comes from https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html, cdk-lib hasn't included this policy yet. hopefully soon. |
I am using distribution HTTP API with cloudfront. And I want to pass
Authorization
header from cloudfront to HTTP API lambda authorizer. And I am not able to whitelist any header from cloudfront.Reproduction Steps
In brand new CDK Projest just create the following policy
What did you expect to happen?
I expcted to successfully deploy the origin policy. I haven't even attached to cloudfront distribution yet.
What actually happened?
The deploy fails with following error
Environment
Other
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: