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

Basic auth fails with non latin characters in username or password #1446

Closed
CameronFraser opened this issue Apr 2, 2018 · 6 comments · Fixed by #1492
Closed

Basic auth fails with non latin characters in username or password #1446

CameronFraser opened this issue Apr 2, 2018 · 6 comments · Fixed by #1492

Comments

@CameronFraser
Copy link

Summary

The usage of btoa for basic auth prevents usage of non latin characters
Not really a big deal as you do not have to use the basic auth and can encode it yourself but thought I'd bring it up at least as passwords are becoming more unique.

requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);

To reproduce try using a password with basic auth that has a ҂ symbol in it or by opening up a console and trying to use the btoa function on a string with a ҂ symbol.

@radreamer
Copy link

radreamer commented Apr 5, 2018

+1

@defdata , you can use next code as a temporary solution:

auth: {
    username,
    password: unescape(encodeURIComponent(password)),
},

@jennynju
Copy link
Contributor

jennynju commented Dec 5, 2019

What's the status of this issue currently?
I also encountered this issue when username includes Unicode.

To Reproduce:

axios.post('/sessions', {}, { auth: { username: '中文', password: 'password' } });

@jennynju
Copy link
Contributor

jennynju commented Dec 6, 2019

Add unescape can fix my issue:
` var request = new XMLHttpRequest();

// HTTP basic authentication
if (config.auth) {
  var username = config.auth.username || '';
  var password = config.auth.password || '';
  requestHeaders.Authorization = 'Basic ' + btoa(unescape(encodeURIComponent(username + ':' + password)));
}`

jennynju added a commit to jennynju/axios that referenced this issue Dec 6, 2019
@m-ruhl
Copy link

m-ruhl commented Jan 21, 2020

I have the same issue..

@dohkoxiaozu
Copy link

What's the status of this issue currently?
I also encountered this issue when username includes Unicode.

To Reproduce:

axios.post('/sessions', {}, { auth: { username: '中文', password: 'password' } });

@JustinBeckwith Is there any solution for fixing this problem?

@offtherailz
Copy link

Sorry @jasonsaayman if I re-post on this issue.
Solution in #1492 encodes only password, but the failure can be caused both from username and password.
Encoding should be done on both, isn't it?

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

Successfully merging a pull request may close this issue.

8 participants