nelmio / NelmioCorsBundle

Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application
https://symfony.com/bundles/NelmioCorsBundle/
MIT License
1.89k stars 108 forks source link

Symfony 5, all urls are ignored #143

Closed melflorance closed 1 year ago

melflorance commented 4 years ago

Hello,

I just installed the bundle with Symfony 5, there were no problems during the installation. The default configuration was ok, until i added a query parameter to the request, and everthing is now ignored.

Here the form of the url i tried to use: 'http://localhost/api/users?page=1

Im using this configuration (the default one):

nelmio_cors:
    defaults:
        origin_regex: true
        allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
        allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
        allow_headers: ['Content-Type', 'Authorization']
        expose_headers: ['Link']
        max_age: 3600
    paths:
        '^/': null

Here is the environment variable i'm using in the .env file:

CORS_ALLOW_ORIGIN=^.*$

I tried a lot of different pattern match for the regex, i tried to remove the regex and hardcode the url, but none of them are working and i can't find any solution.

It's either that the plugin isn't supported by Symfony 5 yet, or that there is something terribly wrong.

Of course it's highly probably that my configuration is wrong, but since i'm using everthing by default and that my regex is quite largely open, i can't get it.

I would greatly appreciate if you could help me on this one.

Thanks

rmbl commented 4 years ago

I've got the same problem on an application that I upgraded from Symfony 4.3 to 5.0. It worked while it was on Symfony 4.3.

ChangePlaces commented 4 years ago

Can confirm, it's stopped working! cache:clear didn't have any effect. "null" is output for the access-control-output-origin header value

andonivianez commented 4 years ago

Another error, that happens when you install this module in a clean Symfony 5 proyect, it´s that this module doesn´t works... you can do this to fix it: Add this to 'config/bundles.php' file (at the end): Nelmio\CorsBundle\NelmioCorsBundle::class => ['dev' => true, 'test' => true]

tomsihap commented 4 years ago

Same here.

jourdan-qe commented 4 years ago

Same here. That's a pity Are there plans to support Sf 5 on the way? Thx

tomsihap commented 4 years ago

Any updates on this one?

aelfannir commented 4 years ago

Same

aelfannir commented 4 years ago

Got the same error again with another project

mvaljento commented 3 years ago

Same here.

Develex commented 3 years ago

same here.

ChangePlaces commented 3 years ago

People, let's learn what the emojis mean please, especially the thumbs-up one. "Same here" is not constructive help.

fd6130 commented 3 years ago

I can't understand the question at all like "The default configuration was ok, until i added a query parameter to the request, and everthing is now ignored."

I'm using this on my Symfony 5 project and so far no problem at all.

simplis-jourdan commented 3 years ago

Hello

Well, I'm digging that topic as I'd like to use NelmioCors on Symfony 5.

So, I included last version (2.1.1) in my project and activated the module for all environments :

Symfony modules

Here is my Nelmio cors config. I voluntary set allow_methods and allow_origin in the default config. GET method is not allowed anywhere

Nelmio cors config

I serve Symfony with its own server on 8000 port. And here is a curl GET request which works the same way nelmio cors would not be activated (400 response is the expected one)

Curl request

Despite the fact the request is allowed, I think the important thing here is there is no access-control-allow-origin headers and other cors headers in the response. Any idea to help solve that (big) issue?

Thank you

Seldaek commented 1 year ago

Closing here as I am not sure what the issue is. I definitely don't have problems on symfony 5 or 6. If someone still has an issue please open a new issue with repro details.

@simplis-jourdan your issue seems to be another issue entirely, you do not set an Origin header, nor a preflight OPTIONS request, so there is nothing the bundle should do.

Nincha commented 1 year ago

As it may help anyone falling back here:

Despite the fact I was originally thinking this was a global issue with Nelmio, I found out Nelmio was working as it should and my issue was relative to that topic instead of this one ; if I'm not mistaken this has to do with statics assets not being concerned by Nelmio.