HTTP 403 Forbidden: why access is refused and how to fix it

Open this example in the tool

Try it in the tool

HTTP Status Codes

Every HTTP status code with its RFC, meaning and when to use it.

Chmod Calculator

Translate 755 ↔ rwxr-xr-x ↔ u=rwx,g=rx,o=rx instantly.

HTTP 403 Forbidden means the server understood the request and refuses to fulfil it. It is defined in RFC 9110, section 15.5.4. Unlike 401, logging in again will not help: the problem is permission, policy or configuration.

Causes on the application side

  • A missing role or scope. The user is signed in but the account may not do this (an editor calling an admin endpoint, a token without the write scope).
  • A resource that belongs to another user, when the application checks ownership.
  • CSRF checks that fail: some frameworks answer 403 when the token is missing or wrong.
  • A feature that is off for your plan, region or account state.

Causes on the infrastructure side

  • A web application firewall or CDN rule blocks the request: a suspicious query string, a known bad bot, a country block, a rate rule. The body is often a page from the CDN, not from your application. Check the firewall events and look for a ray or request ID.
  • An IP allow list, for example an admin area limited to the office.
  • Hot-link protection that denies images when the Referer is another site.
  • A missing index file with directory listing off (nginx: directory index of "/var/www/site/" is forbidden).
  • File permissions and ownership. The web server runs as a user such as www-data or nginx. If that user cannot read the file, or a folder on the way lacks the execute bit, the answer is 403.
  • SELinux or AppArmor denies the access although the Unix permissions look right (check ls -Z and the audit log).
  • Signed URLs (object storage, CDN) that expired or were built with a wrong signature.

Check the file permissions

For ordinary web content the safe defaults are 644 for files and 755 for folders. Open 644 and 755 to see what each digit grants, or paste any mode, such as rw-r-----, into the chmod calculator.

namei -l /var/www/site/index.html   # shows the owner and mode of every folder on the path
ls -ld /var/www/site /var/www/site/index.html

namei -l is the quickest way to find the folder that lacks the execute bit. Do not “fix” a 403 with chmod 777; see why 777 is a bad idea.

Check from the outside

  1. Call the URL with curl -i and read the headers: a server: cloudflare or an x-amz- header tells you which layer answered.
  2. Compare it with and without the credentials, from another network, and with a different User-Agent. If only one of them fails, the cause is a rule on identity or bot detection.
  3. Read the server log; it says why: access forbidden by rule, client denied by server configuration, or a permission error with a path.

Design note: 403 or 404

A 403 says “this exists, but not for you”. When existence is sensitive, return 404 instead, and do it the same way for every unauthorised request, so that the difference cannot be measured. The HTTP status codes tool lists 401, 403 and 404 side by side.

Frequently asked questions

Can I fix a 403 as a visitor?

Only if the cause is on your side: you are signed out, you use the wrong account, a VPN or a shared network is blocked, or the cookies are broken. Try a private window and another network. If a page is simply not for you, only the site owner can change it.

Why does a 403 appear for my own files on the server?

Usually file permissions or ownership: the web server's user cannot read the file, or cannot enter one of the folders on the way to it (the folders need the execute bit). Files are normally 644 and folders 755.

Should I send 403 or 404 for a resource the user must not see?

If it is harmless to say that the resource exists, send 403. If knowing that it exists is itself a leak (for example another user's private page), send 404. Pick one rule and use it consistently.

What does 'directory index of ... is forbidden' mean?

nginx has no index file in that folder (such as index.html) and directory listing is turned off, so it refuses with 403. Add an index file, fix the index directive, or turn on autoindex if listing is what you want.

More in this reference