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

Add Access-Control-Request-Method to the list of forwarded headers - CORS problem #174

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

Conversation

Nyholm
Copy link

@Nyholm Nyholm commented Mar 15, 2022

I (with help from @t-richard) found this small thing that could be a massive improvement.

I am running a API and want to allow request from my React app. I obviously get issues with CORS but no matter how much I try I failed to solve it...

It turned out to be that Chrome is doing a "preflight" to check CORS headers with an OPTION request. The NelmioCorsBundle is checking for the Access-Control-Request-Method. If that header does not exist, the preflight will fail.

I am not sure if this is needed for CORS or if it is needed for CORS with NelmioCorsBundle. I thought I would share it here and hopefully it will help other developers in the same situation.


The workaround would be to configure forward headers yourself like:

constructs:
    website:
        type: server-side-website
        # ...
        forwardedHeaders:
            - Accept
            - Accept-Language
            - Authorization
            - Content-Type
            - Origin
            - Referer
            - User-Agent
            - X-Forwarded-Host
            - X-Requested-With
            - Access-Control-Request-Method

@Nyholm Nyholm changed the title Add Access-Control-Request-Method to the list of forwarded headers Add Access-Control-Request-Method to the list of forwarded headers - CORS problem Mar 15, 2022
@t-richard
Copy link
Contributor

Thanks for opening this PR.

This is a pain and there is no correct way to handle this. For correct CORS handling, we would probably need to also add access-control-request-headers to the list but we would go above the 10 headers limit.

There has been a discussion about possibly increasing the limlit via the AWS support but it never worked on my side ☹️ #136

I really wish AWS Cloudfront would be more flexible here...

In the current situation, I'm not sure if this PR helps because we can't add access-control-request-headers

@Nyholm
Copy link
Author

Nyholm commented Mar 15, 2022

It did help me. I also managed to squeeze in an extra header that I didn’t show in my workaround example.

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

Successfully merging this pull request may close these issues.

None yet

2 participants