NelmioCorsBundle icon indicating copy to clipboard operation
NelmioCorsBundle copied to clipboard

he 'Access-Control-Allow-Origin' header contains multiple values '*, http://localhost', but only one is allowed.

Open antonioperic opened this issue 9 years ago • 12 comments

XMLHttpRequest cannot load http://liveboard-dev.locastic.com/api/v1/login. The 'Access-Control-Allow-Origin' header contains multiple values '*, http://localhost', but only one is allowed. Origin 'http://localhost' is therefore not allowed access.

nelmio_cors:
paths:
    '^/api/':
        allow_origin: ['*']
        allow_headers: ['*']
        allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'OPTIONS']
        max_age: 3600

antonioperic avatar Feb 04 '15 13:02 antonioperic

Not sure what you're saying.. where do you get this error?

Seldaek avatar Feb 09 '15 01:02 Seldaek

After Google Server Side login I got one time code from popup window and with callback function when trying to get login method I got this error

antonioperic avatar Feb 09 '15 08:02 antonioperic

The Access-Control-Allow-Origin header is actually returning whatever origin was sent to it (see code) so if you get an invalid one like that I'd say it's because the origin header of the request was set incorrectly.

Seldaek avatar Feb 09 '15 16:02 Seldaek

@antonioperic Afaik you can’t combine * with other values. Either use just * or list all domains individually.

hacfi avatar May 31 '15 14:05 hacfi

@Seldaek @hacfi this is error I got

"NetworkError: 400 Bad Request - http://api.peribian.com/api/v1/login" login Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api.peribian.com/api/v1/login. (Reason: CORS preflight channel did not succeed). Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api.peribian.com/api/v1/login. (Reason: CORS request failed).

and this is nelmio config

nelmio_cors:
   paths:
       '^/api/':
           allow_origin: ['http://app.peribian.com']
           allow_headers: ['Authorization, X-Requested-With, Content-Type, Accept, Origin']
           allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'OPTIONS']
           max_age: 3600

I am trying from app.peribian.com get api.peribian.com/api/v1/ but keep getting that error

screenshot:http://take.ms/GKtoS

antonioperic avatar Jun 06 '15 12:06 antonioperic

@antonioperic Check the php error log / Symfony error log. I don’t think there is an issue with this bundle but I could be wrong.

hacfi avatar Jun 07 '15 00:06 hacfi

Your allow_headers config is wrong, you're having one big string with commas there, while it should be an array of header strings, i.e.:

 allow_headers: ['Authorization', 'X-Requested-With', 

'Content-Type', 'Accept', 'Origin']

Seldaek avatar Jun 08 '15 08:06 Seldaek

@Seldaek will try it. previously I had * there but didn't work

antonioperic avatar Jun 08 '15 08:06 antonioperic

I faced the same issue when I had CORS configured on the Apache side and with this bundle. I removed the apache configuration to get this to work.

devantoine avatar Apr 18 '16 12:04 devantoine

Symfonys boiler plate nginx config has the line - add_header 'Access-Control-Allow-Origin' '*';

# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
    add_header 'Access-Control-Allow-Origin' '*';
    fastcgi_pass php:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    # When you are using symlinks to link the document root to the
    # current version of your application, you should pass the real
    # application path instead of the path to the symlink to PHP
    # FPM.
    # Otherwise, PHP's OPcache may not properly detect changes to
    # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
    # for more information).
    fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
}

Comment out the line - add_header 'Access-Control-Allow-Origin' '*'; This will not add the additional 'Access-Control-Allow-Origin' header to the response header

armourjami avatar Jun 21 '17 11:06 armourjami

@armourjami but does symfony has a boilerplate nginx conf file? if so... where? also, i was in prod env when this happened to me. after i've downgraded the nelmio bundle i got rid of the problem.

toriqo avatar Jun 29 '17 09:06 toriqo

Same problem here. If i disable the whole Nelmio bundle both headers disapear

11mb avatar May 21 '18 17:05 11mb