In case of brute force attack, what is the right status code that a REST api should return for a locked user? Actually, when a user fails password three times in last 3 minutes a lock its account.
If he try to login the fourth time, it receive a response with {"success":"false"}
with status code 401. Is it formally right or not?
While attempting to brute-force a login page, you should pay particular attention to any differences in: Status codes: During a brute-force attack, the returned HTTP status code is likely to be the same for the vast majority of guesses because most of them will be wrong.
The account lockout policy “locks” the user's account after a defined number of failed password attempts. The account lockout prevents the user from logging onto the network for a period of time even if the correct password is entered.
A locked account can't be used until you reset it or until the number of minutes specified by the Account lockout duration policy setting expires. You can set a value from 1 through 999 failed sign-in attempts, or you can specify that the account will never be locked by setting the value to 0.
If you determine that your application is under attack, you could return 418
(I'm a teapot) and use a "short and stout" message in the response payload.
For HTTP authentication (stateless and sending the credentials in the Authorization
header) use 401
(Unauthorized) to indicate that the credentials have been refused for that request.
Assuming that the credentials are valid but the user account is locked (or in any other condition that prevents the server from accepting the request), you could use 403
(Forbidden) and a descriptive message in the payload. Quote from the RFC 7235:
A server that receives valid credentials that are not adequate to gain access ought to respond with the
403
(Forbidden) status code.
403 means that "yes, I know about you, and your credentials might even be valid, but I am rejecting you anyway". Whether that be due to a lockout, your IP is banned, the phase of the moon isn't the correct one, etc, you can use this to signal that the request was invalid for that reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With