Skip to content

Commit d41d5ae

Browse files
committed
fix(cors): add Origin to allowed headers
This is not implied and needs to be added explicitly
1 parent c0e0f6c commit d41d5ae

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/corsHeaders.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void describe('corsHeaders()', () => {
1313
{
1414
'Access-Control-Allow-Credentials': true,
1515
'Access-Control-Allow-Headers':
16-
'content-type, accept, if-match, authorization',
16+
'accept, authorization, content-type, if-match, origin',
1717
'Access-Control-Expose-Headers':
1818
'x-amzn-requestid, etag, apigw-requestid',
1919
'Access-Control-Allow-Methods': 'PUT, DELETE, POST, GET, PATCH',

src/corsHeaders.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ export const corsHeaders = (
3535
'Access-Control-Allow-Credentials': true,
3636
'Access-Control-Allow-Origin': origin({ headers }),
3737
'Access-Control-Allow-Methods': allowedMethods.join(', '),
38-
'Access-Control-Allow-Headers':
39-
'content-type, accept, if-match, authorization',
38+
'Access-Control-Allow-Headers': Array.from(
39+
new Set(['content-type', 'accept', 'if-match', 'authorization', 'origin']),
40+
)
41+
.map((h) => h.trim())
42+
.sort((h1, h2) => h1.localeCompare(h2))
43+
.join(', '),
4044
'Access-Control-Expose-Headers': 'x-amzn-requestid, etag, apigw-requestid',
4145
'Access-Control-Max-Age': cacheForSeconds,
4246
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin#cors_and_caching

0 commit comments

Comments
 (0)