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

Adding xsrf configuration option to allow for toggling of XSRF protection #98

Closed
wants to merge 3 commits into from

Conversation

skevy
Copy link

@skevy skevy commented Aug 3, 2015

New default is disabled. Potentially breaking change for some, but enables axios to work on client-side JS platforms other than the browser (e.g. react-native).

@skevy
Copy link
Author

skevy commented Aug 3, 2015

Would help with #70, though without further testing I'm not sure it would fully resolve.

@skevy
Copy link
Author

skevy commented Aug 3, 2015

I'm confused about this test failure...not sure it has anything to do with my code. Seems like a configuration issue.

@davidfou
Copy link
Contributor

davidfou commented Aug 4, 2015

I had the same problem. I opened a PR which fixes your problem. Have a look at #100 😄

@skevy
Copy link
Author

skevy commented Aug 4, 2015

awesome. Thanks @DFournier! I'll wait to fix until #100 is merged and then I'll rebase.

@mzabriskie
Copy link
Member

@skevy try rebasing. Also, let's call the flag xsrfEnabled, and default it to true.

@skevy
Copy link
Author

skevy commented Sep 2, 2015

@mzabriskie should be all set. Sorry for the delay on this :)

@mzabriskie
Copy link
Member

@skevy I was just about to merge this, when I had a thought. Why do we need a config option? I think that axios should be smart enough to know when it is not in a browser environment, and gracefully skip the XSRF stuff itself. This would allow it to work in a web worker as well.

Basically let's get rid of config.xsrfEnabled, keep your changes to lib/xhr.js, but test for typeof window !== 'undefined'.

@skevy
Copy link
Author

skevy commented Sep 25, 2015

@mzabriskie while I think the idea is right, I'm not sure what the best way to detect that would be. At the moment, especially when running in debug mode, there's really no way to easily tell whether RN is a browser or not. There's an open proposal to add something to navigator to help with this: facebook/react-native#1331

@mzabriskie
Copy link
Member

@skevy would it matter if react-native is running in the browser? In that case it will try adding the xsrf cookie as a header to the request. But if the cookie doesn't exist, no harm done. The real problem is avoiding a reference to window.location or document.cookie when they don't exist. In debug mode they exist, and we're no worse for the wear.

@mzabriskie
Copy link
Member

I had @tylermcginnis do some testing for me. Here are the findings:

window.location: {host: "localhost:8081"}
document.cookie: ""
document.createElement: null

These are the only browser specific references that axios is using for xsrf protection. I believe that if we test around these conditions, we can make axios work in react-native.

@tylermcginnis
Copy link

Let me know if you need any more help, glad to help.

@axios axios locked and limited conversation to collaborators May 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants