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


  • 2019-10-24 01:14:29

    通过属性搜索商品mysql设计

    属性是可以动态扩展的,问题:属性是搜索条件 问:请展示出 材质为塑料 防水为YES,颜色为绿色的商品详细信息,按照sort_filed排序

  • 2019-10-25 15:18:18

    Vue.use Vue.prototype区别

    1、不是为了vue写的插件(插件内要处理)不支持Vue.use()加载方式 2、非vue官方库不支持new Vue()方式 3、每一个vue组件都是Vue的实例,所以组件内this可以拿到Vue.prototype上添加的属性和方法。

  • 2019-10-25 23:33:45

    php制作漂亮的随机颜色标签云效果

    代码中的array里面的字符串就是各种随机色的编码,大家可以根据自己的需求来配置颜色。 然后input1里面是字体大小的随机代码,也可以自行修改。

  • 2019-10-27 00:23:42

    mac卡住,强制关闭应用

    要正常退出(关闭)Mac 应用,请从菜单栏的应用菜单中选取“退出”,或按下 Command (⌘)-Q。如果应用不退出,请按照以下步骤强制该应用退出。

  • 2019-10-27 11:02:10

    mac不要输入sudo,免密设置

    mac有时候使用终端进行操作,会让输入sudo 并且要输入命令,这要很啰嗦,浪费时间,我们得想办法去掉。

  • 2019-10-27 11:08:11

    Mac系统移到废纸篓的快捷键是什么

    用Windows键盘上的delete键和del键都不能删除文件,那么在Mac系统移到废纸篓的快捷键是什么?答:在移到废纸篓的快捷键组合就是Command + delete,可以将文件删除到废纸篓。清空废纸篓的快捷键是 Command + shift + delete​。