Saltar al contenido ForoHackers

Embarrassing question: 401 or 403?

Diseño de APIHTTP
#1037 · anónimo · · Denunciar

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 · anónimo · · Denunciar

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 · anónimo · · Denunciar

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 · anónimo · · Denunciar

I have done this for years

Welcome to the club. We have a laminated card.

Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder