Skip to content

Commit 4e9f66d

Browse files
committed
improve login check, #577 #434
Signed-off-by: Stefan Seide <account-github@seide.st>
1 parent ae01863 commit 4e9f66d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* update ioredis from 4.28.5 to 5.4.1
2626
* update dependencies yargs@17.7.2, ejs@3.1.10, jstree@3.3.17, config@3.3.12, body-parser@1.20.3
2727
* update "@cyclonedx/cyclonedx-npm"@1.19.3
28+
* improve password login check and prevent timing attacks on username check
2829

2930
## Version 0.8.1
3031
#### Bugfixes

lib/app.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let config = require('config');
1818

1919

2020
function comparePasswords(a, b) {
21-
// make shure booth buffers have same length and make time comparision attacks to
21+
// make sure booth buffers have same length and make time comparison attacks to
2222
// guess pw length harder by calculation fixed length hmacs first
2323
let key = crypto.pseudoRandomBytes(32);
2424
let bufA = crypto.createHmac('sha256', key).update(a).digest();
@@ -232,13 +232,13 @@ module.exports = function (_redisConnections) {
232232
// signin with username and password
233233
// explicit casts as fix for possible numeric username or password
234234
// no fast exit on wrong username to let evil guy not guess existing ones
235-
let validUser = true;
235+
let validUser = false;
236236
let validPass = false;
237-
if (String(req.body.username) !== String(config.get('server.httpAuth.username'))) {
238-
validUser = false;
237+
if (comparePasswords(String(req.body.username), String(config.get('server.httpAuth.username')))) {
238+
validUser = true;
239239
}
240240
if (config.get('server.httpAuth.passwordHash')) {
241-
validPass = bcrypt.compare(String(req.body.password), String(config.get('server.httpAuth.passwordHash')))
241+
validPass = bcrypt.compareSync(String(req.body.password), String(config.get('server.httpAuth.passwordHash')))
242242
}
243243
else {
244244
// prevent empty passwords

0 commit comments

Comments
 (0)