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(next-export): CORS errors due to wrong crossorigin default value #58200

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

ild0tt0re
Copy link

If corsOrigin is not specified in nextConfig it become false and in the following code

crossOrigin: nextConfig.crossOrigin || '',

It fallback to empty string '' , but this is wrong since the default value should be undefined otherwise we are forcing the client to use ALWAYS CORS for assets as you can see from the MDN Official crossorigin spec

some crossorigin values can be:

  • anonymous: Request uses CORS headers and credentials flag is set to 'same-origin'. There is no exchange of user credentials via cookies, client-side TLS certificates or HTTP authentication, unless destination is the same origin.
  • "": Setting the attribute name to an empty value, like crossorigin or crossorigin="", is the same as anonymous.

By default (that is, when the attribute is not specified), CORS is not used at all. The user agent will not ask for permission for full access to the resource and in the case of a cross-origin request, certain limitations will be applied based on the type of element concerned:

You can see the Current vs. Expected behavior in the issue

Fixes #57931

@kyun
Copy link

kyun commented Feb 21, 2024

Is this still working on?

@stepan-twnty
Copy link

@ijjk can you approve it?

@dgattey
Copy link

dgattey commented Feb 22, 2024

Any updates on this fix? This fixes a critical bug still present in Next 14.1 with CORS attributes being incorrectly required

@samithaf
Copy link

samithaf commented Mar 2, 2024

@leerob could you please review?

Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

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

Hi, can we add a test case for this to prevent regressing?

@Xavier59
Copy link

Xavier59 commented Mar 6, 2024

Can we just merge it and add regression test later @ijjk ?
Everybody using CDN to serve content has been stuck on 13.5.2 for months.
Thanks

@konstk1
Copy link

konstk1 commented May 1, 2024

Is this abandoned? We are also having an issue with crossorigin scripts.

@samithaf
Copy link

samithaf commented May 3, 2024

While it may not be a solution for everyone, we solved this issue by fronting the Next.js applications with a CDN and then route the static assets to a static storage (Azure Blobs but can be anything depend on which cloud provider you are using). Then we route dynamic paths to web compute tier via CDN.

Given static paths going to be relative now, you are not going to face any CORS issues anymore.

@willholmeswastaken
Copy link

Suffering from this issue myself too... hopefully we get some answers on this soon.

@akbortoli
Copy link

Is this abandoned? We are having to patch every version for it to work via CDN.

@Xavier59
Copy link

Hello @ijjk please review again for merge. Lot of people suffering from this issue and there is no update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crossorigin is added to scripts tags on static generated pages [next version > 13.5.2]
10 participants