Web Technology Basics

On a members-only website, an ordinary member who is logged in requests a page that only administrators may access. The server knows who the user is but does not allow access to this page. Which of the following status codes is most appropriate to return?

  1. A401 Unauthorized
  2. B403 Forbidden
  3. C404 Not Found
Show answer and explanation

Answer: B. 403 Forbidden

403 Forbidden indicates that the server understood the request but refuses to allow access. Despite its name, 401 Unauthorized is the code for missing or invalid authentication information, and the WWW-Authenticate header tells the client how to authenticate. Here the server has confirmed who the user is and what is lacking is permission (authorization), so 403 applies. Some designs deliberately return 404 to avoid revealing that an admin page exists, but the code that describes the situation as it is is 403.

  • A. 401 is used when authentication information is missing or invalid. This user has already authenticated.
  • B. Correct. It indicates that the user is authenticated but lacks permission.
  • C. 404 indicates that the resource was not found. Some designs use it to hide a page's existence, but the code that describes the situation as it is is 403.
Practice this topic Back to topic

Books on Web Technology Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Web Technology Basics questions

  1. A web API returns data in JSON format as the body of its response. Which of the following headers is generally added to the response to indicate the format of the body?
  2. A browser requests an image it received earlier once again, putting the ETag value from that earlier response into the If-None-Match header. If the image on the server has not changed, which of the following is the correct server response?
  3. Which of the following correctly describes HTTP/2 and HTTP/3?
  4. From a web server with an RTT of 40 ms, one HTML file and the four images it references are fetched one after another. Assume that establishing a TCP connection takes one round trip and each request and response take one round trip, and ignore data transfer time, server processing time, TLS and connection teardown. Which of the following is the difference in total time between opening a new TCP connection for each object and reusing one TCP connection (a persistent connection)?
  5. HTTP is a stateless protocol. Which of the following correctly describes what this means together with the usual way a website keeps a user logged in?