Skip to content
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

fix: re-map authorization header when using secured function urls #215

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/lambdas/sign-fn-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ describe('LambdaOriginRequestIamAuth', () => {
const event = getFakePageRequest();
const request = event.Records[0].cf.request;
await signRequest(request);
const securityHeaders = ['x-amz-date', 'x-amz-security-token', 'x-amz-content-sha256', 'authorization'];
const securityHeaders = [
'x-amz-date',
'x-amz-security-token',
'x-amz-content-sha256',
'authorization',
'origin-authorization',
];
const hasSignedHeaders = securityHeaders.every((h) => h in request.headers);
expect(hasSignedHeaders).toBe(true);
});
Expand All @@ -35,6 +41,12 @@ function getFakePageRequest(): CloudFrontRequestEvent {
request: {
clientIp: '1.1.1.1',
headers: {
authorization: [
{
key: 'Authorization',
value: 'Bearer token',
},
],
host: [
{
key: 'Host',
Expand Down
5 changes: 5 additions & 0 deletions src/lambdas/sign-fn-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export function cfHeadersToHeaderBag(headers: CloudFrontHeaders): Bag {
// not destructured) is case sensitive. we arbitrarily use case insensitive key
for (const [headerKey, [{ value }]] of Object.entries(headers)) {
headerBag[headerKey] = value;
// if there is an authorization from CloudFront, move it as
// it will be overwritten when the headers are signed
if (headerKey === 'authorization') {
headerBag['origin-authorization'] = value;
}
}
return headerBag;
}
Expand Down
Loading