Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CORS origins of an array of one are made a scalar. #1536

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

inlined
Copy link
Member

@inlined inlined commented Mar 8, 2024

The access-control-allowed-origins CORS header only allows a single origin or "*" as its response. To support multiple origins, the cors middleware makes this header dynamic based on the referrer header of the request when the middleware is configured with anything but a single string.

To help avoid a few edge cases customers may encounter, we can unwrap an array of one element into a scalar to encourage the cors middleware to make the access-control-allowed-origin header static.

As a very minor performance boost, this change also instantiates the cors middleware once and uses it on all requests rather than constructing it dynamically within a request.

The access-control-allowed-origins CORS header only allows
a single origin or "*" as its response. To support multiple origins,
the cors middleware makes this header dynamic based on the origin
header of the request when the middleware is configured with anything
but a single string.

To help avoid a few edge cases customers may encounter, we can unwrap
an array of one element into a scalar to encourage the cors middleware
to make the access-control-allowed-origin header static.

As a very minor performance boost, this change also instantiates the
cors middleware once and uses it on all requests rather than
constructing it dynamically within a request.
@inlined inlined merged commit 0aaedc4 into master Mar 19, 2024
13 checks passed
// on the origin header of the request. If there is only one element in the
// array, this is unnecessary.
if (Array.isArray(origin) && origin.length === 1) {
origin = origin[1];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bug... shouldn't this either be origin = origin[0] or origin = undefined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤬 Will fix this week

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants