Is it OK to return a HTTP 401 for a non existent resource instead of 404 to prevent information disclosure?

Actually, the W3C recommends (RFC 2616 §10.4.4 403 Forbidden) doing the opposite. If someone attempts to access a resource, but is not properly authenticated, return 404 then, rather than 403 (Forbidden). This still solves the information disclosure issue.

If the server does not wish to make
this information available to the
client, the status code 404 (Not
Found) can be used instead.

Thus, you would never return 403 (or 401). However, I think your solution is also reasonable.

EDIT: I think Gabe’s on the right track. You would have to reconsider part of the design, but why not:

  • Not found – 404
  • User-specific insufficient permission – 404
  • General insufficient permission (no one can access) – 403
  • Not logged in – 401

Leave a Comment