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

fix: Allow brackets in www-authentication header values #341

Merged
merged 1 commit into from
Jan 7, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Allow brackets in www-authentication header values
  • Loading branch information
TimBailey-pnk committed Jan 7, 2021
commit 079e533165e30832d61f17ec7150ecc902f3fc64
2 changes: 1 addition & 1 deletion lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var digest = {};

digest.parse_header = function(header) {
var challenge = {},
matches = header.match(/([a-z0-9_-]+)="?([a-z0-9=\/\.@\s-\+]+)"?/gi);
matches = header.match(/([a-z0-9_-]+)="?([a-z0-9=\/\.@\s-\+)()]+)"?/gi);

for (var i = 0, l = matches.length; i < l; i++) {
var parts = matches[i].split('='),
Expand Down
38 changes: 38 additions & 0 deletions test/auth_digest_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,44 @@ describe('auth_digest', function() {
});
});

describe('With brackets in realm header', function() {
it('should generate a proper header', function() {
// from https://tools.ietf.org/html/rfc2617
var performDigest = function() {
var header = 'Digest qop="auth", realm="IP Camera(76475)", nonce="4e4449794d575269597a706b5a575935595441324d673d3d", stale="FALSE", Basic realm="IP Camera(76475)"';
var user = 'Mufasa';
var pass = 'Circle Of Life';
var method = 'get';
var path = '/dir/index.html';

var updatedHeader = auth.digest(header, user, pass, method, path);
var parsedUpdatedHeader = parse_header(updatedHeader);

var ha1 = md5(user + ':' + parsedUpdatedHeader.realm + ':' + pass);
var ha2 = md5(method.toUpperCase() + ':' + path);
var expectedResponse = md5([
ha1,
parsedUpdatedHeader.nonce,
parsedUpdatedHeader.nc,
parsedUpdatedHeader.cnonce,
parsedUpdatedHeader.qop,
ha2
].join(':'));

return {
header: updatedHeader,
parsed: parsedUpdatedHeader,
expectedResponse: expectedResponse,
}
}

const result = performDigest();

(result.header).should
.match(/realm="IP Camera\(76475\)"/)
});
});

describe('Without qop (RFC 2617)', function() {
it('should generate a proper header', function() {
// from https://tools.ietf.org/html/rfc2069
Expand Down