Skip to the content ForoHackers
Log inJoin

Embarrassing question: 401 or 403?

API designHTTP
#1037 · anonymous · · Report

senior-ish dev building an API every time I need to return an auth error I open a tab to check 401? 403? 404? I have done this for years the tab is always the same article

Please just tell me the rule, once, in a way that I will remember.

#1522 · anonymous · · Report

401 = "I do not know who you are" (it is badly named; it means unauthenticated). The response should carry a WWW-Authenticate header saying how to authenticate.

403 = "I know who you are, and you may not do this".

Memory trick: 401 -> log in and try again. 403 -> logging in again will not help.

#1523 · anonymous · · Report

404 is a legit third choice when even admitting the resource exists would leak information (private repos, other tenants' ids). Pick one policy and apply it everywhere, or the difference between 403 and 404 becomes the leak.

#1524 · anonymous · · Report

I have done this for years

Welcome to the club. We have a laminated card.

Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply