Skip to content

Basic authentication gets (double?) escaped #5158

@matanarbel

Description

@matanarbel

Describe the bug

I'm sending a GET request with basic authentication, where the username contains @ - so I'm escaping it to %40.
Username: my@email.com
Password: pass
URL: http://my%40email.com:pass@127.0.0.1:3000

When using Axios 0.27.2 - it works propely, but when I tried Axios 1.1.3 the authentication failed.
To debug it, I built a server that prints the credentials from the request, and I saw that using Axios 0.27.2, the received username was my@email.com, but with version 1.1.3 the received username was my%40email.com (and that's why the auth failed).

I also tried to send the request without escaping it (which looks weird, but I gave it a go - http://my@email.com:pass@127.0.0.1:3000) and the result was the same (failed).

To Reproduce

Run server.js:

const express = require('express');
const basicAuth = require('basic-auth');
let app = express();
app.get('/', function (req, res) {
    let user = basicAuth(req);
    console.log(user.name); //prints username
    console.log(user.pass); //prints password
});
app.listen(3000, function () {});

Then run this code twice - once with Axios 0.27.2 and once with 1.1.3:

const axios = require('axios');
axios.get('http://my%40email.com:pass@127.0.0.1:3000');

Test result after running with Axios 0.27.2:

my@email.com
pass

Test result after running with Axios 1.1.3:

my%40email.com
pass

Code snippet

No response

Expected behavior

I expect the Basic auth username to be sent without further encoding (my@email.com in the example above) - just like in Axios 0.27.2

Axios Version

1.1.3

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

16.14.2

OS

Windows 11, CentOS Linux 7 (Core)

Additional Library Versions

No response

Additional context/Screenshots

No response

Metadata

Metadata

Assignees

Labels

issue::bugThis issue is related to a bug that requires fixing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions