fix!: api login should not suggest which credential is wrong (#32159)
parent
16f5c59510
commit
552b2550a7
@ -0,0 +1,7 @@ |
||||
--- |
||||
"@rocket.chat/meteor": major |
||||
--- |
||||
|
||||
Api login should not suggest which credential is wrong (password/username) |
||||
|
||||
Failed login attemps will always return `Unauthorized` instead of the internal fail reason |
||||
@ -1,14 +0,0 @@ |
||||
// Do not disclose if user exists when password is invalid
|
||||
import { Accounts } from 'meteor/accounts-base'; |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
const { _runLoginHandlers } = Accounts; |
||||
Accounts._runLoginHandlers = function (methodInvocation, options) { |
||||
const result = _runLoginHandlers.call(Accounts, methodInvocation, options); |
||||
|
||||
if (result.error && result.error.reason === 'Incorrect password') { |
||||
result.error = new Meteor.Error(403, 'User not found'); |
||||
} |
||||
|
||||
return result; |
||||
}; |
||||
@ -0,0 +1,16 @@ |
||||
// Do not disclose if user exists when password is invalid
|
||||
import { Accounts } from 'meteor/accounts-base'; |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
const { _runLoginHandlers } = Accounts; |
||||
|
||||
Accounts._options.ambiguousErrorMessages = true; |
||||
Accounts._runLoginHandlers = async function (methodInvocation, options) { |
||||
const result = await _runLoginHandlers.call(Accounts, methodInvocation, options); |
||||
|
||||
if (result.error instanceof Meteor.Error) { |
||||
result.error = new Meteor.Error(401, 'User not found'); |
||||
} |
||||
|
||||
return result; |
||||
}; |
||||
Loading…
Reference in new issue