-
-
Notifications
You must be signed in to change notification settings - Fork 957
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
Library erroneously URI-encodes usersname and password #2093
Comments
Lines 1842 to 1883 in e032b60
Line 1044 in e032b60
Lines 1060 to 1063 in e032b60
show otherwise. Can you please post an actual code to reproduce the issue? The one you posted isn't valid. |
I can reproduce the bug in v11.8.5, but not v12.3.0. I can't upgrade to version 12 because using ES modules would require an entire refactor of our build system. |
Here's how to reproduce: 'use strict';
const http = require('http');
const Got = require('got');
const client = Got.extend({
username: 'admin',
password: 'special_chars_^#@',
});
const server = http.createServer((req, res) => {
const auth = req.headers.authorization;
if (!auth || !auth.startsWith('Basic ')) {
return res.writeHead(401).end();
}
const base64Creds = auth.slice(6);
const plainCreds = Buffer.from(base64Creds, 'base64').toString();
const [username, password] = plainCreds.split(':');
console.log('username: %s\npassword: %s', username, password);
return res.writeHead(204).end();
});
server.listen(0, () => {
const { port } = server.address();
client.get(`http://localhost:${port}`).finally(() => server.close());
}); It outputs:
|
Lines 1690 to 1702 in 5e17bb7
In Got v11 we don't do any special handling. The bug is in upstream, see nodejs/node#31450 Duplicate of #1169 |
Describe the bug
When
Got
builds anAuthorization
header for basic auth, it URI-encodes the username and password. This is not warranted by any spec, and it breaks requests that use special characters in their username or password.Actual behavior
Got URI-encodes the username and password used in the
Authorization
header for basic auth.Expected behavior
Got should send whatever username or password is specified by the user, without modification.
Code to reproduce
Checklist
The text was updated successfully, but these errors were encountered: