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

Remove case sensitivity check for scheme and parameters name in Digest Auth #1394

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/authorizer/digest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ var _ = require('lodash'),
'uri'
],

nonceRegex = /nonce="([^"]*)"/,
realmRegex = /realm="([^"]*)"/,
qopRegex = /qop="([^"]*)"/,
opaqueRegex = /opaque="([^"]*)"/,
nonceRegex = /nonce="([^"]*)"/i,
realmRegex = /realm="([^"]*)"/i,
qopRegex = /qop="([^"]*)"/i,
opaqueRegex = /opaque="([^"]*)"/i,
codenirvana marked this conversation as resolved.
Show resolved Hide resolved
_extractField,
SHA512_256,
nodeCrypto;
Expand Down Expand Up @@ -140,7 +140,8 @@ _extractField = function (string, regexp) {
*/
function _getDigestAuthHeader (headers) {
return headers.find(function (property) {
return (property.key.toLowerCase() === WWW_AUTHENTICATE) && (_.startsWith(property.value, DIGEST_PREFIX));
return (property.key.toLowerCase() === WWW_AUTHENTICATE) &&
(_.startsWith(String(property.value).toLowerCase(), DIGEST_PREFIX.toLowerCase()));
});
}

Expand Down
35 changes: 26 additions & 9 deletions test/fixtures/auth-requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
}
}
},
"digestWithQueryParams": {
"url": "https://postman-echo.com/digest-auth?key=value",
"digestWithoutAdvanceData": {
"url": "https://postman-echo.com/digest-auth",
"method": "GET",
"header": [],
"data": {
Expand All @@ -52,17 +52,34 @@
"type": "digest",
"digest": {
"username": "postman",
"realm": "Users",
"password": "password",
"nonce": "bcgEc5RPU1ANglyT2I0ShU0oxqPB5jXp",
"nonceCount": "00000001",
"algorithm": "MD5",
"qop": "",
"clientNonce": "0a4f113b",
"opaque": "5ccc069c403ebaf9f0171e9517f40e"
"clientNonce": "0a4f113b"
}
}
},
"digestWithQueryParams": {
"url": "https://postman-echo.com/digest-auth?key=value",
"method": "GET",
"header": [],
"data": {
"mode": "formdata",
"content": []
},
"auth": {
"type": "digest",
"digest": {
"username": "postman",
"realm": "Users",
"password": "password",
"nonce": "bcgEc5RPU1ANglyT2I0ShU0oxqPB5jXp",
"nonceCount": "00000001",
"algorithm": "MD5",
"qop": "",
"clientNonce": "0a4f113b",
"opaque": "5ccc069c403ebaf9f0171e9517f40e"
}
}
},
"oauth1": {
"auth": {
"type": "oauth1",
Expand Down
35 changes: 35 additions & 0 deletions test/unit/auth-handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,41 @@ describe('Auth Handler:', function () {
});

describe('digest', function () {
it('should add the Auth header when we have upper case scheme and parameters names', function () {
var request = new Request(rawRequests.digestWithoutAdvanceData),
auth = request.auth,
authInterface = createAuthInterface(auth),
handler = AuthLoader.getHandler(auth.type),
digestData = auth.digest.members,
digestDataObject = {},
expectedDigestData = {
username: 'postman',
password: 'password',
nonce: '123abc',
realm: 'newRealm',
qop: 'auth',
clientNonce: '0a4f113b',
nonceCount: '00000001'
},
response = {
code: 401,
headers: [
{
key: 'WWW-Authenticate',
value: 'digest Realm="newRealm", Nonce="123abc", Qop="auth"'
}
]
};

handler.post(authInterface, response, _.noop);

_.forEach(digestData, function ({ value, key }) {
digestDataObject[key] = value;
});

expect(digestDataObject).to.eql(expectedDigestData);
});

it('should add the Auth header for (algorithm="MD5", qop=""', function () {
var request = new Request(rawRequests.digest),
auth = request.auth,
Expand Down