Skip to content

Commit bac1e6a

Browse files
feat: add timing safe equal comparison
* chore: add [email protected] as dependency * feat: add timing safe equal comparison Co-authored-by: Blake Embrey <[email protected]>
1 parent d3b6a63 commit bac1e6a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var timingSafeCompare = require('tsscmp');
12
var http = require('http');
23

34
/*!
@@ -53,7 +54,9 @@ module.exports = function basicAuth(callback, realm) {
5354
if ('string' != typeof password) throw new Error('password argument required');
5455
realm = arguments[2];
5556
callback = function(user, pass){
56-
return user == username && pass == password;
57+
const usernameValid = timingSafeCompare(user, username);
58+
const passwordValid = timingSafeCompare(pass, password);
59+
return usernameValid && passwordValid;
5760
}
5861
}
5962

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
"url": "https://github.com/expressjs/basic-auth-connect/issues"
1919
},
2020
"devDependencies": {
21+
"connect": "*",
2122
"mocha": "*",
2223
"should": "*",
23-
"supertest": "*",
24-
"connect": "*"
24+
"supertest": "*"
2525
},
2626
"scripts": {
2727
"test": "make test"
28+
},
29+
"dependencies": {
30+
"tsscmp": "^1.0.6"
2831
}
2932
}

0 commit comments

Comments
 (0)