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

Blank passwords result in different Auth headers #681

Closed
ncase opened this issue Oct 11, 2013 · 0 comments · Fixed by #690
Closed

Blank passwords result in different Auth headers #681

ncase opened this issue Oct 11, 2013 · 0 comments · Fixed by #690

Comments

@ncase
Copy link

ncase commented Oct 11, 2013

Some web services have RESTful APIs where you authenticate using your API key as your username and a blank password. I was using such a service, when I was stopped by this bug which only happens with blank passwords:

request.get(url).auth("username","",true);

will send a different Authentication header than

request.get(url, {
    auth: {
        user: "username",
        pass: "",
        sendImmediately: true
    }
});    

Even though these two should be functionally identical.

To demonstrate this bug, I used RequestBin to log my HTTP requests, and indeed, these two different methods result in different Authentication headers being sent. Please run the following code for yourself and see the results here.

var request = require('request');

var requestBin = "http://requestb.in/14iakdo1"; // Go to http://requestb.in to create a new bin
var username = "username";
var password = "";

// Authorization: Basic dXNlcm5hbWU6
request.get(requestBin).auth(username,password,true);

// Authorization: Basic dXNlcm5hbWU6dW5kZWZpbmVk
// This Auth header is WRONG.
request.get(requestBin, {
    auth: {
        user: username,
        pass: password,
        sendImmediately: true
    }
});

I'd just use the first method, but it means I can't have my extra options or callback.

Which is a bummer.


UPDATE: Changing auth.pass to auth.password sends the correct Auth header, somehow.

// Authorization: Basic dXNlcm5hbWU6
request.get(requestBin, {
    auth: {
        user: username,
        password: password,
        sendImmediately: true
    }
});

UPDATE 2: This might explain why there's an extra "dW5kZWZpbmVk" in the wrong Auth header: http://www.base64decode.org/dec/dW5kZWZpbmVk/

diversario added a commit to diversario/request that referenced this issue Oct 24, 2013
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.

1 participant