Cloudfront: Allow "Authorization" as a header in Origin Request Policies #28883
Labels
@aws-cdk/aws-cloudfront
Related to Amazon CloudFront
effort/medium
Medium work item – several days of effort
feature-request
A feature should be added or improved.
p3
Describe the feature
I want the ability to forward the Authorization header to the origin server, without putting it in the cache key. This is the purpose of the Origin Request Policies.
See issue for prior discussion.
Use Case
I have various endpoints which each determine by themselves what they want to cache, and if they want to cache in the CDN or locally.
e.g.
/user/profile
takes a user's id from their JWT to provide the right info when a user views their own profile. In this case I need theAuthorization
to be forwarded to the origin server to serve the right request. I don't want to cache it publicly, so I won't return any cache headers./books?genre=fantasy&sort=latest
gets the latest fantasy books. In this case I don't need theAuthorization
header to go to the origin server, it's a public request. However it's an expensive request, so I want to cache it publicly. I want to include the query params in the cache key, but not theAuthorization
header.As far as I can see, to do this I would create a cache policy and an origin request policy, as below, but this is not possible because
Authorization
is not allowed in origin request policies.Proposed Solution
Allow
Authorization
as a header in origin request policiesOther Information
Right now my workaround is using a separate cache behaviour with a path pattern, and adding
public
to any api path which is public, and not forwardingAuthorization
there to either the origin server or the cache key. I would much rather have this logic live inside my app server than my CDN config.I don't ever need
Authorization
to be included in a cache key, there are too many users for that to be useful and I'll just use the browser cache instead.Acknowledgements
CDK version used
Not relevant
Environment details (OS name and version, etc.)
Not relevant
The text was updated successfully, but these errors were encountered: