HTTP 401 Unauthorized or 403 Forbidden for a “disabled” user?

前端 未结 3 1167
独厮守ぢ
独厮守ぢ 2021-02-01 04:15

An authentication service allows user accounts be disabled (a sort of soft-delete).

If the server then receives an authentication request for a disabled user that would

3条回答
  •  渐次进展
    2021-02-01 04:39

    I've got two different answers for what to return in this case.

    Semantic choice - 401 Unauthorized. In this case, your client has provided credentials, and the request has been refused based on the specific credentials. If the client were to try again with a different set of credentials, or if the account were to be re-enabled in the future, the same request might succeed.

    Security choice - 404 Not Found. Many services will simply return a 404 for any failure, in order to avoid information leakage. Github comes to my mind immediately.

    From General API Information, in github's developer docs:

    Unauthenticated requests will return 404 to prevent any sort of private information leakage.

    For something I was deploying as a public service, I'd probably go with using 404 to avoid giving an attacker clues about their credential attempts. If it was for internal-only consumption, or in testing, I'd probably return 401.

提交回复
热议问题