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

偶然发现的axios bug #12

Open
xchunzhao opened this issue Dec 26, 2019 · 0 comments
Open

偶然发现的axios bug #12

xchunzhao opened this issue Dec 26, 2019 · 0 comments

Comments

@xchunzhao
Copy link
Owner

xchunzhao commented Dec 26, 2019

问题描述

一个React-Native项目,排查其中某个问题。通过抓包发现请求都带上了cookie从而导致了一个意外的问题。
经排查发现,项目中并没有显示设置axios配置withCredentials:true
Axios文档中明确说明withCredentials默认为false

问题定位

问题来了,难道是默认值没有生效?

于是手动设置了withCredentials:false

仍然不生效...

进一步猜测会不会是axios到达native层由于某种机制或者限制被篡改了呢?

发现了React-Native中的XMLHttpRequest

lA3mVJ.jpg

withCredentials默认值为true。否定了之前的猜测,只有一步步debug axios源码看看端倪。

axios/lib/adapters/xhr.js#L132

lAWdBD.md.png
这部分代码问题就很明显了,如果设置了withCredentials:false, 不会走到这部分代码块中,从而导致设置的withCredentials:false会被忽略。

解决

lA8EWt.png

详细描述可以看看这个 PR

最后

记录问题,记录排查问题的过程。

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

No branches or pull requests

1 participant