Merge pull request #14825 from overleaf/jpa-debug-bcrypt-get-rounds

[web] add debug logging for bcrypt.getRounds calls

GitOrigin-RevId: 3fe8dca1d188f4e65d666da19f4bd4697623b7a6
This commit is contained in:
Jakob Ackermann
2023-09-13 16:13:33 +02:00
committed by Copybot
parent 9cb017487a
commit 8aefa058b8

View File

@@ -70,9 +70,41 @@ const AuthenticationManager = {
if (!user || !user.hashedPassword) {
return callback(null, null, null)
}
let rounds = 0
try {
rounds = bcrypt.getRounds(user.hashedPassword)
} catch (err) {
let prefix, suffix, length
if (typeof user.hashedPassword === 'string') {
length = user.hashedPassword.length
if (user.hashedPassword.length > 50) {
// A full bcrypt hash is 60 characters long.
prefix = user.hashedPassword.slice(0, '$2a$12$x'.length)
suffix = user.hashedPassword.slice(-4)
} else if (user.hashedPassword.length > 20) {
prefix = user.hashedPassword.slice(0, 4)
suffix = user.hashedPassword.slice(-4)
} else {
prefix = user.hashedPassword.slice(0, 4)
}
}
logger.warn(
{
err,
userId: user._id,
hashedPassword: {
type: typeof user.hashedPassword,
length,
prefix,
suffix,
},
},
'unexpected user.hashedPassword value'
)
}
Metrics.inc('bcrypt', 1, {
method: 'compare',
path: bcrypt.getRounds(user.hashedPassword),
path: rounds,
})
bcrypt.compare(password, user.hashedPassword, function (error, match) {
if (error) {