CORS: credentials mode is 'include'

2017-11-10 00:06:15

XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:5000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

答案

The issue stems from your Angular code:

When withCredentials is set to true, it is trying to send credentials or cookies along with the request. As that means another origin is potentially trying to do authenticated requests, the wildcard ("*") is not permitted as the "Access-Control-Allow-Origin" header.

You would have to explicitely respond with the origin that made the request in the "Access-Control-Allow-Origin" header to make this work.

I would recommend to explicitely whitelist the origins that you want to allow to make authenticated requests, because simply responding with the origin from the request means that any given website can make authenticated calls to your backend if the user happens to have a valid session.

I explain this stuff in this article I wrote a while back.

So you can either set withCredentials to false or implement an origin whitelist and respond to CORS requests with a valid origin whenever credentials are involved


  • 2021-01-15 13:30:21

    MongoDb web 用户界面

    MongoDB 的 Web 界面访问端口比服务的端口多1000。 如果你的MongoDB运行端口使用默认的27017,你可以在端口号为28017访问web用户界面,即地址为:http://localhost:28017。

  • 2021-01-16 09:31:14

    Xcode两种引入图片的方法

    如果是纯代码,图片名需要手动添加@2x,@3x等倍数标识,且需要指明后缀.png,.jpg;IB添加图片的话只需要指明后缀就好,不用添加倍数标识。

  • 2021-01-16 09:39:32

    iOS 更改状态栏、导航栏颜色,电池颜色

    注意事项,两种方法设置View controller-based status bar appearance 的值不一样,并且如果你的plist里面没有View controller-based status bar appearance,你需要新建一个。然后就可以成功了。

  • 2021-01-16 09:45:19

    tabbar的titlePositionAdjustment设置文字距离

    指定相应的数据去偏移一个位置,向右或者向下为正值,向左或者向上为负值,不过首先你得有一个相对位置的坐标。而tabbarItem文字的坐标是底部为x轴,y轴则是tabbarItem的centerX;

  • 2021-01-16 09:49:13

    Cocoapods如何查看项目中引入库的版本号

    项目中已经安装过Cocoapods,并生成了Podfile.lock文件。 打开终端,cd命令切换到项目中的Podfile.lock文件目录下,执行命令:cat Podfile.lock 即可。也可以用文本方式打开 Podfile.lock 文件。示例如下: