Skip to content

Commit

Permalink
bcrypt: reject passwords > 72 bytes (#1389)
Browse files Browse the repository at this point in the history
bcrypt truncates input to 72 bytes before hashing, so accepting passwords above this length can lead to surprising results.
  • Loading branch information
alxndrsn authored Feb 12, 2025
1 parent 8387cbe commit ad40043
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/model/query/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ update.audit = (user, data) => (log) => log('user.update', user.actor, { data: d
const updatePassword = (user, cleartext) => ({ run }) =>
(cleartext.length < 10
? reject(Problem.user.passwordTooShort())
: hashPassword(cleartext))
: Buffer.from(cleartext).length > 72
? reject(Problem.user.passwordTooLong())
: hashPassword(cleartext))
.then((hash) => run(sql`update users set password=${hash} where "actorId"=${user.actor.id}`));
updatePassword.audit = (user) => (log) => log('user.update', user.actor, { data: { password: true } });

Expand Down
2 changes: 2 additions & 0 deletions lib/util/problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ const problems = {

encodingNotSupported: problem(400.37, () => 'Encoding not supported.'),

passwordTooLong: problem(400.38, () => 'The password or passphrase provided exceeds the maximum length.'),

// no detail information for security reasons.
authenticationFailed: problem(401.2, () => 'Could not authenticate with the provided credentials.'),

Expand Down

0 comments on commit ad40043

Please sign in to comment.