skip to content

questions

page 1 of 2

In HTTP, what is the difference between status 401 Unauthorized and status 403 Forbidden, and what header must a 401 response carry?

level: juniorimportance: must knowfreq 85%

answer

  1. 401 = unauthenticated, 403 = unauthorized
  2. 401 MUST carry WWW-Authenticate challenge
  3. Expired token → 401, not 403
  4. 403 confirms existence → 404 to hide
  5. Clients refresh on 401, give up on 403

basics

~20 s

401 means authentication is missing or invalid — the server asks "who are you?" and must send a WWW-Authenticate header. 403 means the identity is known (or irrelevant) and the request is still refused; retrying with credentials will not help.

solid answer

~50 s

**401 Unauthorized** really means *unauthenticated*: no credentials were sent, or the ones sent could not be validated (missing, malformed, expired, bad signature). RFC 9110 requires a 401 to include a `WWW-Authenticate` header naming at least one challenge scheme, e.g. `WWW-Authenticate: Bearer realm="api", error="invalid_token"`. It is an invitation to retry with credentials. **403 Forbidden** means the server understood the request and refuses to authorize it. Re-authenticating will not change the outcome: the caller lacks the role or scope, crosses a tenant boundary, or is blocked by policy (IP allowlist, licence, disabled account). 403 is also correct for an anonymous request to something that is simply never public. Rule of thumb: **401 = fix your credentials; 403 = your credentials are fine and still not enough.** Returning 403 for an expired token is a classic bug — clients key their silent-refresh logic off 401, so a 403 makes them log the user out instead of refreshing.

code

http · 9 lines
http
GET /api/orders/42 HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOi...expired

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="api", error="invalid_token", error_description="token expired"
Content-Type: application/json

{"code":"TOKEN_EXPIRED","message":"Access token expired"}

go deeper

for a junior

Recall the pair crisply: 401 = who are you / credentials missing or invalid; 403 = known and refused. Mention that 401 asks the client to authenticate.

for a middle

Add the mandatory WWW-Authenticate challenge, the expired-token-is-401 rule, and the concrete effect on client refresh interceptors.

for a senior

Discuss existence-hiding with 404, consistent policy per resource family, and separating 401 vs 403 in logs and dashboards to diagnose key rotation versus role misconfiguration.

for a principal

Frame it as a platform contract: one error taxonomy across services so gateways, SDKs and clients agree on which failures are retryable, plus a deliberate information-disclosure policy for object-level authorization.

## Two different questions HTTP splits "you cannot have this" into two answers. **Authentication** asks *who are you?*; **authorization** asks *are you allowed?* Status **401** is a negative answer to the first, **403** to the second. The names mislead. 401 is spelled "Unauthorized" but means *unauthenticated*. 403 is "Forbidden" and is the real authorization failure. Reading them as "401 = no identity, 403 = identity insufficient" removes almost all confusion. ## 401 and the mandatory challenge RFC 9110 says a 401 response **MUST** include a `WWW-Authenticate` header field containing at least one challenge applicable to the target resource. A challenge names an authentication scheme and optional parameters: - `WWW-Authenticate: Basic realm="admin"` — browsers respond by popping the native credential dialog. - `WWW-Authenticate: Bearer realm="api", error="invalid_token", error_description="expired"` — the OAuth 2.0 bearer form (RFC 6750), which lets a client distinguish *expired* from *malformed* and decide whether to refresh. A 401 without any challenge is technically non-conformant, and it is also less useful: the client has no machine-readable hint about how to authenticate. Many APIs ship this bug because a framework filter writes a bare 401. Typical 401 triggers: no `Authorization` header at all; expired or revoked access token; bad signature; wrong audience/issuer on a JWT; session cookie unknown to the store. ## 403 and what it means operationally 403 says: request understood, authorization refused, **do not retry as-is**. The typical causes are role/scope failures (a valid token without the `orders:write` scope), object-level checks (a user asking for a record belonging to another tenant), and non-identity policy (geo-block, IP allowlist, suspended account, read-only maintenance mode). RFC 9110 also allows a server to return 403 rather than reveal that it *could* have succeeded with different credentials. An anonymous request to a never-public resource is a judgement call. If the endpoint accepts credentials, 401 with a challenge is friendlier: it tells the client what to do. If credentials could never help — say, the resource is disabled — 403 is honest. ## The refresh-flow trap Almost every SPA and mobile client implements the same interceptor: *on 401, try the refresh token once, replay the request; on 403, surface a "not allowed" error*. If the API returns 403 for an expired token, users get spurious permission errors and forced logouts. Conversely, if the API returns 401 for a genuine permission failure, clients enter refresh loops — refresh succeeds, request fails 401 again, repeat. Getting this pair right is a contract with your own clients, not pedantry. ## When to hide existence instead A 403 confirms the resource exists. For sensitive object IDs (another tenant's invoice, a private repository) that is an information leak — an attacker can enumerate IDs and read existence from the status code. The common hardening is to return **404** for objects the caller may not see, and reserve 403 for cases where existence is already known to the caller. Pick one policy per resource family and apply it consistently; mixing 403 and 404 for the same class of object re-creates the oracle you were trying to close. ## Body and observability Both statuses may carry a body. Use a machine-readable error shape (a stable `code` plus a human `message`); never echo the token or the internal policy rule that failed. On the server side, log which check failed and the subject identifier — the single most common production complaint is "we return 403 and nobody can tell why". Distinguish, in logs and metrics, authentication failures from authorization failures: a spike in 401s usually means a clock skew, key rotation, or expired secret; a spike in 403s usually means a bad role migration or a misconfigured policy.

  • A client sends a valid but expired access token. Which status do you return and why?
    401, with `WWW-Authenticate: Bearer error="invalid_token"`. Expiry is an authentication failure: the credential is no longer valid, and retrying with a fresh token will succeed. Clients key their silent-refresh interceptors off 401, so returning 403 here causes spurious logouts.
  • An authenticated user requests another tenant's record. Is 403 or 404 the better response?
    Both are defensible. 403 is literally accurate but confirms the record exists, letting an attacker enumerate IDs. For sensitive resources, return 404 so that "absent" and "not yours" are indistinguishable. Whatever you choose, apply it uniformly across the resource family, otherwise the inconsistency itself leaks existence.
  • Is it legal to return 401 without a WWW-Authenticate header?
    No — RFC 9110 makes the header mandatory on 401 responses, and it must contain at least one challenge. Many frameworks emit a bare 401 anyway, so clients still work, but you lose the machine-readable signal that tells a client which scheme to use and why the credential was rejected.

saying these in an interview costs you the question

  • Saying 401 means "you are logged in but not allowed" — that is 403
  • Returning 403 for expired or missing tokens, breaking client refresh flows
  • Omitting WWW-Authenticate on 401 responses
  • Believing 403 must never be used for anonymous requests
  • Returning 200 with an error body instead of 401/403 "because the client handles it"

context

open as a page

What do the HTTP methods GET and POST actually mean on the wire, and what determines which one an operation should use?

level: juniorimportance: must knowfreq 85%

basics

~20 s

GET requests a representation of a resource — retrieval only, parameters in the URL, no intended side effects. POST asks the target resource to process the enclosed representation according to its own semantics — creating, submitting, or triggering work, with data in the body.

open as a page

What does the HTTP HEAD method do, how must its response relate to the response a GET on the same URL would produce, and what should the Content-Length header say in a HEAD response?

level: juniorimportance: must knowfreq 55%

basics

~20 s

HEAD asks for exactly what GET would return, minus the response body. The status line and headers must match the GET response, so Content-Length states the size of the body that GET would have sent, even though HEAD sends zero bytes.

open as a page

What is the difference between HTTP status 301 and HTTP status 302, and what does each one tell a browser, a cache, and a search engine to do?

level: juniorimportance: must knowfreq 70%

basics

~20 s

Both send the client to the URL in the Location header. 301 Moved Permanently says the resource has a new home — clients and caches may store it indefinitely and search engines transfer ranking. 302 Found says it is temporary — keep using the original URL, and do not cache by default.

open as a page

In HTTP, what does it mean for a request method to be "safe" versus "idempotent", and which of the standard methods have each property?

level: juniorimportance: must knowfreq 78%

basics

~20 s

Safe means the method is read-only: the client asks for nothing to change. Idempotent means sending the identical request many times leaves the server in the same state as sending it once. GET, HEAD, OPTIONS, TRACE are safe (and therefore idempotent); PUT and DELETE are idempotent but not safe; POST and PATCH are neither by definition.

open as a page

An HTTP client receives a response with status code 227, which it has never seen before. What should it do with that response, and what general rule about HTTP status code classes governs the decision?

level: juniorimportance: must knowfreq 76%

basics

~20 s

Judge it by the first digit. 227 is 2xx, so treat it exactly like 200 OK. HTTP requires clients to understand the five classes (1xx interim, 2xx success, 3xx redirection, 4xx client error, 5xx server error), not every individual code.

open as a page

How do the HTTP methods PUT and PATCH differ in what the request body means, and what does RFC 5789 require of a PATCH payload?

level: middleimportance: must knowfreq 75%

basics

~20 s

A PUT body is the complete desired representation of the target — the server replaces the resource with it, so omitted fields are dropped. A PATCH body is a set of change instructions in a patch format (RFC 5789), applied to the current representation, so only named parts change.

open as a page

HTTP added status codes 307 and 308 alongside the older 301 and 302. What problem do they solve, and what happens to the request method and body when a client follows each of the four?

level: middleimportance: must knowfreq 55%

basics

~20 s

301 and 302 were widely implemented by rewriting POST to GET and dropping the body, so method preservation became unpredictable. 307 (temporary) and 308 (permanent) forbid changing the method: the client re-sends the same method and body to the new URL.

open as a page

A client calls DELETE on a resource and gets HTTP 204; the identical DELETE is sent again and returns HTTP 404. Has the server broken DELETE's idempotency guarantee? Explain what that guarantee actually covers.

level: middleimportance: must knowfreq 62%

basics

~20 s

No. Idempotency constrains the server's end state, not the response. After one DELETE or five, the resource is gone — that is the guarantee. Returning 204 then 404 is legitimate. Returning 204 both times is equally legitimate; pick one and document it.

open as a page

Walk through the difference between HTTP status codes 500, 502, 503 and 504. For each one, say who is failing and what the code tells the caller.

level: middleimportance: must knowfreq 78%

basics

~20 s

500: the origin server hit an unhandled error. 502: a gateway got an invalid or unusable response from upstream. 503: the server is reachable but temporarily unable to serve. 504: a gateway timed out waiting for upstream.

open as a page

An HTTP client sends a request, the TCP connection drops, and no response ever arrives. Under HTTP's own rules, when may the client automatically retry that request, and what must it never retry automatically?

level: seniorimportance: must knowfreq 55%

basics

~20 s

A client may automatically retry only if the method is idempotent (GET, HEAD, OPTIONS, TRACE, PUT, DELETE) and it received no response — or if the server explicitly signalled the request was not processed. Never auto-retry POST or PATCH: a lost response is indistinguishable from a lost request, so the retry may duplicate the effect.

open as a page

The HTTP status codes 400 Bad Request and 422 Unprocessable Content are both client errors. What does each one mean per the HTTP specifications, and how do generic caches, proxies and clients treat them on the wire?

level: middleimportance: should knowfreq 55%

basics

~20 s

400: the server could not parse or accept the message itself — malformed syntax, framing or unparseable content. 422: the media type was understood and the syntax parsed, but the server cannot process the instructions. Both are client errors; neither is auto-retryable or cacheable by default.

open as a page

What is the difference between HTTP status 404 Not Found and 410 Gone, and when is each the right choice?

level: middleimportance: should knowfreq 45%

basics

~20 s

404 says the server found no current representation and gives no promise about the past or future — the resource may appear later. 410 says the resource existed, is intentionally and permanently gone, and clients and crawlers should stop asking and remove links.

open as a page

When must an HTTP server respond with 405 Method Not Allowed, what header is mandatory on that response, and how does it differ from 501 Not Implemented?

level: middleimportance: should knowfreq 40%

basics

~20 s

405 means the target resource exists but does not support the method used. RFC 9110 requires the response to include an Allow header listing the methods it does support, e.g. Allow: GET, HEAD, PUT. 501 means the server does not recognise or implement the method at all.

open as a page

What is the HTTP OPTIONS method for, what does the Allow response header contain, and what does the request line `OPTIONS * HTTP/1.1` mean?

level: middleimportance: should knowfreq 45%

basics

~20 s

OPTIONS asks what communication options are available for a target. The server answers with an Allow header listing the HTTP methods that target supports, such as Allow: GET, HEAD, OPTIONS. The asterisk form OPTIONS * targets the server or proxy itself, not any resource.

open as a page

What does HTTP status 303 See Other mean, and how is it used in the Post/Redirect/Get pattern after a browser form submission?

level: middleimportance: should knowfreq 45%

basics

~20 s

303 See Other tells the client to fetch a different URL with GET, whatever method the original request used. After a form POST the server replies 303 with Location pointing at a result page, so the browser lands on a plain GET that is safe to refresh, bookmark, and revisit with the back button.

open as a page

Is the HTTP PATCH method idempotent? Explain what determines the answer and how you would make a PATCH endpoint safe to repeat.

level: middleimportance: should knowfreq 45%

basics

~20 s

Not by definition. RFC 5789 leaves PATCH non-idempotent because the patch document decides: setting a field to a fixed value repeats harmlessly, but appending to an array or incrementing a number does not. An individual endpoint can be idempotent — but generic clients must not assume it.

open as a page

HTTP defines GET as a "safe" method. What exactly does safety promise, what breaks in production when a GET endpoint changes state, and are server-side effects like logging a violation?

level: middleimportance: should knowfreq 50%

basics

~20 s

Safe means the client does not request any state change, so the user cannot be held accountable for side effects. Server-side bookkeeping — logs, hit counters, cache warming — is allowed because the user didn't ask for it. Mutating GETs get triggered by crawlers, prefetchers and link-preview bots.

open as a page

What does the HTTP Retry-After header mean on a 503 Service Unavailable response, what value formats may it take, and how should a well-behaved client honour it?

level: middleimportance: should knowfreq 50%

basics

~20 s

Retry-After tells the client how long to wait before retrying. Its value is either a number of seconds (delta) or an HTTP-date. On a 503 it is a hint about when service resumes; clients should wait at least that long and add jitter.

open as a page

What is an HTTP 1xx interim response, and how does an exchange that includes 100 Continue or 103 Early Hints differ from an ordinary request/response pair?

level: middleimportance: should knowfreq 40%

basics

~20 s

A 1xx is a non-final response: status line plus headers, never a body, and a final response still follows on the same exchange. 100 Continue tells a client waiting with Expect: 100-continue to send its request body; 103 Early Hints sends preload links before the real response.

open as a page

Which HTTP status codes are defined to carry no response content, and what goes wrong on the wire if a server writes body bytes with a 204 No Content or 304 Not Modified?

level: middleimportance: should knowfreq 50%

basics

~20 s

All 1xx responses plus 204 No Content, 205 Reset Content and 304 Not Modified never carry content; neither does any response to HEAD. Extra body bytes desynchronize an HTTP/1.1 connection: the recipient reads them as the start of the next response.

open as a page

What does HTTP status 409 Conflict mean, and give concrete situations where it is the right answer rather than 400 or 422?

level: seniorimportance: should knowfreq 45%

basics

~20 s

409 means the request is well-formed and valid but conflicts with the current state of the target resource — a duplicate unique key, a lost-update on concurrent edits, or an illegal state transition. The body should explain the conflict so the client can resolve and resubmit.

open as a page

How should an HTTP service signal rate limiting with status 429 Too Many Requests, and what are the two legal formats of the Retry-After header?

level: seniorimportance: should knowfreq 55%

basics

~20 s

Return 429 when a client exceeded its request quota, and include Retry-After telling it when to come back. Retry-After takes either delta-seconds (Retry-After: 120) or an HTTP-date (Retry-After: Wed, 21 Oct 2026 07:28:00 GMT). Clients should back off, not retry immediately.

open as a page

Which success status codes are appropriate for POST, PUT and DELETE responses, and what does the Location header mean in that context?

level: seniorimportance: should knowfreq 50%

basics

~20 s

POST that creates returns 201 with Location pointing at the new resource; other POSTs return 200 with a result, 202 if queued, or 204 if nothing to return. PUT returns 201 when it created the resource, otherwise 200 with the representation or 204. DELETE returns 204, 200 with a result, or 202 if asynchronous.

open as a page

Explain what the HTTP CONNECT method does, how a browser uses it to reach an HTTPS site through a forward proxy, and what the proxy can and cannot observe once the tunnel is established.

level: seniorimportance: should knowfreq 35%

basics

~20 s

CONNECT asks a proxy to open a raw TCP connection to a host:port and then relay bytes blindly. The browser sends CONNECT example.com:443, gets 200, then performs TLS end-to-end through the tunnel. The proxy sees host, port, timing and byte counts — not URLs, headers, or bodies.

open as a page

You changed a URL that had previously been served with an HTTP 301 Moved Permanently redirect, but returning users still land on the old destination while new users go to the right place. What is happening, and how do you recover?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Their browsers cached the 301. Because 301 is cacheable by default and browsers persist it, those clients never contact your server for that URL. You cannot invalidate a browser cache remotely — fix it by serving a correcting redirect from the old destination, or by changing the URL so the cache key differs.

open as a page

Your load balancer's access logs show a burst of HTTP 502 and 504 responses, while the application servers behind it log almost no errors. How do you work out where the failure actually is?

level: seniorimportance: should knowfreq 55%

basics

~20 s

Split by code: 502 means the proxy could not get a valid response (crashes, resets, closed keep-alives, oversized headers); 504 means upstream was too slow. Correlate proxy and origin logs on a request id, then check process restarts, connection reuse and timeout budgets.

open as a page

You are moving a large, heavily linked site and its API to a new domain. How do you choose among HTTP status codes 301, 302, 307 and 308 for the redirects, and what operational risks do you plan for?

level: principalimportance: should knowfreq 28%

basics

~20 s

Sequence it: serve temporary redirects (302 for pages, 307 for API writes) while validating the mapping, then promote to permanent (301, 308) once stable. Plan for one-hop chains, dropped Authorization across origins, cookie and CORS breakage, redirect loops, and keeping the old domain alive for years.

open as a page

You own a platform where dozens of services call each other over HTTP. How would you set policy for which 5xx status code each service returns under overload, dependency failure and deploy, and how should client retry behaviour and the Retry-After header follow from that policy?

level: principalimportance: should knowfreq 38%

basics

~20 s

Make the codes mean something fleet-wide: 503 for deliberate, temporary refusal (overload, drain, open breaker) with Retry-After; 500 only for genuine defects; never hand-write 502/504, which belong to proxies. Then let the shared client retry on 503/502 with jitter and budgets, and require idempotency for anything else.

open as a page

What does HTTP status 501 Not Implemented mean, and when is it the correct response for a server to send?

level: middleimportance: nice to knowfreq 30%

basics

~20 s

501 means the server does not support the functionality needed to fulfil the request at all — typically it does not recognise or implement the request method for any resource. It is about a missing capability, not a missing or wrong resource.

open as a page

showing 1–30 of 33