A 403 Forbidden error means the server understood your request and refuses to fulfil it. Unlike a 404, the resource may well exist. Unlike a 401, logging in again usually won't help, because the server already knows (or doesn't care) who you are and has decided you're not allowed.
Where the fix lies depends on who you are. For a visitor, the usual causes are a VPN or IP block, a firewall such as Cloudflare blocking your browser, stale cookies, or a page you genuinely don't have permission to see. For a site owner, it's usually file permissions, a missing index file with directory listing disabled, or a deny rule in Nginx, Apache, IIS or .htaccess. For a developer, a 403 typically means the user is authenticated but fails an authorization policy, or a cloud storage request lacks the right role, policy or signature. Jump to the section that fits; there's a layer-by-layer checklist at the end.
What 403 means, and how it differs from 401 and 404
RFC 9110, the current HTTP specification, defines 403 like this: the server understood the request but refuses to fulfil it. If credentials were provided, the server considers them insufficient, and the client should not automatically repeat the request with the same credentials. The spec adds two details that matter in practice. A server may explain the reason in the response body, but it doesn't have to. And a server that wants to hide that a forbidden resource exists may return 404 instead; GitHub does this for private repositories.
Roughly, a server decides in this order:
Request arrives
↓
Can the server parse it? No → 400 Bad Request
↓ Yes
Does it know who you are? No, and auth is required → 401 Unauthorized
↓ Yes (or auth not needed)
Are you allowed to do this? No → 403 Forbidden
↓ Yes
Does the resource exist? No → 404 Not Found
↓ Yes
200 OK
The names don't help. "401 Unauthorized" really means "unauthenticated":
Code | Meaning | Typical cause | Will logging in help? |
|---|
401 Unauthorized | No valid credentials were provided | Missing or expired token, wrong password | Yes, usually |
403 Forbidden | Identity is known or irrelevant, but access is refused | Missing role, IP block, file permissions, WAF rule | Usually no, unless you switch to an account with access |
404 Not Found | The server can't find the resource, or won't admit it exists | Wrong URL, deleted page, hidden private resource | No |
One protocol difference: a 401 response must include a WWW-Authenticate header telling the client how to authenticate, while a 403 has no such requirement. For a comparison that also brings in 409 Conflict, see Are you confused between 401, 403 and 409?
If you're a visitor
Work through the things you control first, roughly in this order.
Look at the URL. One that points at a folder rather than a page, such as one ending in /images/, often returns 403 because directory listing is disabled. Go back to the home page and click through from there.
Check which account you're using. Admin pages, paid content and private documents return 403 when your account lacks access, so sign out and back in or switch accounts. For Google Docs, SharePoint and similar tools, request access from the owner.
Clear the site's cookies. Corrupted or stale session cookies can make a site treat you as unauthorized. Clear cookies for that one site and reload, or try a private window to confirm.
Disconnect your VPN or proxy. Many sites block known VPN, proxy and data center IP ranges, or whole countries, and a VPN exit IP can also carry a poor reputation from other users' traffic. If the page loads once you disconnect, the block was IP-based. Trying another network makes the same test: if it works on mobile data but not on office Wi-Fi, your network's IP is blocked or a company proxy is interfering.
A Cloudflare page showing Error 1020: Access denied means a firewall rule set by the site owner blocked you. Web application firewalls block requests that look automated or malicious, and browser extensions, an unusual user agent or a shared IP with a bad reputation can all trigger them. Cloudflare's advice to visitors is to send the site owner a screenshot of the error, which includes a Ray ID they can look up.
If none of that works, only the site owner can fix it. Send them the URL, the time and any reference ID from the error page.
If it's your site
Start with the server's error log. It nearly always states the exact reason, and the reason tells you which of the sections below applies.
"Permission denied": Linux file permissions and SELinux
The web server user (www-data on Debian and Ubuntu, nginx or apache on RHEL-based systems) must be able to read the file and traverse every parent directory. A single directory without the execute bit is enough to cause a 403, which is why namei is the first tool to reach for:
# Show permissions on every component of the path
namei -l /var/www/example.com/public/index.html
# Common safe defaults: directories 755, files 644
sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;
# Make sure the owner is sensible
sudo chown -R deploy:www-data /var/www/example.com
Never "fix" a 403 with chmod -R 777. It makes every file writable by every user and process on the server.
On RHEL, Fedora, Rocky or AlmaLinux, SELinux can cause a 403 even when the permissions look right. Check the context and restore it:
ls -Z /var/www/example.com
sudo restorecon -Rv /var/www/example.com
Nginx
Nginx writes the reason to /var/log/nginx/error.log, and three messages cover most cases. directory index of "/var/www/site/" is forbidden means there's no index file and autoindex is off. open() "..." failed (13: Permission denied) is the permissions or SELinux problem above. access forbidden by rule means a deny directive matched. A config that avoids the first and uses the third deliberately looks like this:
server {
listen 80;
server_name example.com;
root /var/www/example.com/public;
# Make sure an index file is defined and exists
index index.html index.php;
location / {
try_files $uri $uri/ /index.html;
}
# Restrict an admin area by IP; everyone else gets 403
location /admin/ {
allow 203.0.113.10;
deny all;
}
}
After any change, run sudo nginx -t and then sudo systemctl reload nginx.
Apache and .htaccess
Apache logs AH01630: client denied by server configuration when a Require rule blocks the request, and AH01276: Cannot serve directory when there's no index file and indexes are disabled.
<Directory /var/www/example.com/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
DirectoryIndex index.html index.php
If the main config is fine, suspect .htaccess. Look for old Apache 2.2 syntax such as Order deny,allow and Deny from all, which may still be honoured if mod_access_compat is enabled; Require ip rules that no longer match your users; and security plugin rules, common on WordPress, that block by country or user agent. The quickest test is to rename .htaccess temporarily. If the 403 disappears, the problem is in that file.
IIS and its 403.x sub-status codes
IIS is the easiest of the three to diagnose, because it adds a sub-status code that says exactly what went wrong. Find it in the detailed error page (enable detailed errors locally) or in the sc-substatus field of the IIS log under inetpub\logs\LogFiles. Microsoft's IIS HTTP status code reference has the full list; these are the ones you'll meet:
Code | Meaning | Typical fix |
|---|
403.1 | Execute access forbidden | Grant Execute (scripts) permission on the handler mapping |
403.2 | Read access forbidden | Enable Read; make sure the default document exists |
403.4 | SSL required | Use HTTPS, or redirect HTTP to HTTPS instead of refusing it |
403.6 | IP address rejected | Review IP and Domain Restrictions |
403.7 | Client certificate required | Install a client certificate or relax SSL settings |
403.14 | Directory listing denied | Add a default document or enable directory browsing |
403.16 | Client certificate untrusted or invalid | Fix the certificate chain or trust store |
403.18 | Can't execute URL in the current application pool | Put the custom error page in the same app pool |
403.502 | Maximum request rate limit reached | Tune Dynamic IP Restrictions |
403.503 | IP address denied | Remove the IP from the deny list |
By far the most common is 403.14. With ASP.NET Core it often means the app didn't start, so IIS fell back to serving the folder as static content; check that the ASP.NET Core Hosting Bundle is installed and that web.config references the ASP.NET Core Module. For a static site, set a default document such as index.html or default.aspx:
<configuration>
<system.webServer>
<defaultDocument enabled="true">
<files>
<add value="index.html" />
</files>
</defaultDocument>
<!-- Only if you really want folder listings -->
<!-- <directoryBrowse enabled="true" /> -->
</system.webServer>
</configuration>
HTTP Error 403.14 - Forbidden walks through it in more detail. One trap: NTFS permission problems in IIS often surface as 401.3, not 403. The fix is to grant the app pool identity (for example IIS AppPool\MyAppPool) read access to the site folder.
Visitors see 403 but your logs are empty
Then the edge is blocking them before the request reaches you. In Cloudflare, search Security Events for the Ray ID or client IP from the visitor's error, find the rule that matched, and adjust it or add an allow rule. Bot protection, country blocks and rate limiting are the usual suspects. Also check hosting-level firewalls, such as ModSecurity or a control panel WAF, which may be blocking your CDN's own IP ranges.
Search engines won't index pages that return 403, so a WAF that blocks crawlers can push pages out of search results. Make sure your bot rules allow verified search engine crawlers.
If you're writing the code
In application code, 403 has a precise meaning: authenticated, but not authorized. That gives you a simple rule for your own APIs. Return 401 when the caller hasn't authenticated or the token is invalid or expired. Return 403 when the caller is authenticated but lacks permission. And if admitting that a resource exists is itself a leak, return 404.
Unexpected 403s in ASP.NET Core
ASP.NET Core follows that rule: a challenge produces 401, and a forbid produces 403 when an authenticated user fails a policy or role requirement.
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer();
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("CanManageOrders", policy =>
policy.RequireRole("Admin")
.RequireClaim("scope", "orders.write"));
});
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
// Valid token without the Admin role or scope → 403
app.MapDelete("/orders/{id}", (int id) => Results.NoContent())
.RequireAuthorization("CanManageOrders");
When a user who should have access gets a 403, the role claim type is the first thing I'd check. Identity providers often put roles in a claim named roles or a URI rather than the one ASP.NET Core expects, so set TokenValidationParameters.RoleClaimType to match, and inspect the token at a decoder such as jwt.ms. Next, confirm you're checking the right thing: delegated tokens carry scopes (scp), while app-only tokens carry app roles (roles). And remember that code calling Forbid() or IAuthorizationService.AuthorizeAsync may be denying correctly, for example when a user tries to edit someone else's record.
Cookie authentication has its own quirk. A forbid becomes a redirect to AccessDeniedPath (by default /Account/AccessDenied), which is wrong for API endpoints. Return a real 403 there instead:
builder.Services.ConfigureApplicationCookie(options =>
{
options.Events.OnRedirectToAccessDenied = context =>
{
if (context.Request.Path.StartsWithSegments("/api"))
{
context.Response.StatusCode = StatusCodes.Status403Forbidden;
return Task.CompletedTask;
}
context.Response.Redirect(context.RedirectUri);
return Task.CompletedTask;
};
});
For a broader list of API hardening steps, see ASP.NET Core security best practices for modern web APIs.
Is it CORS or a real 403?
A CORS failure is enforced by the browser, not the server. The console says "blocked by CORS policy" and your JavaScript gets no response, even if the server actually returned 200. That isn't a 403. The real confusion runs the other way. Some services, Azure Blob Storage and Amazon S3 among them, answer the preflight OPTIONS request with 403 when no CORS rule matches. A genuine 403 from your API may lack CORS headers, so the browser reports a CORS error and hides the real status. And a WAF or front door that blocks OPTIONS requests breaks every preflight. In each case the Network tab shows the truth; the console doesn't.
Amazon S3 Access Denied
S3 returns 403 for both explicit denies (a Deny statement matched) and implicit denies (no Allow statement matched), so the error alone doesn't tell you which. Work through the usual causes:
- The IAM policy lacks the action, for example
s3:GetObject on arn:aws:s3:::bucket/*. - A bucket policy, Service Control Policy or VPC endpoint policy denies it.
- Block Public Access is on while you expect public reads.
- The object is encrypted with a KMS key the caller can't use.
- A presigned URL has expired, or the signature doesn't match because of the wrong region, clock skew or changed headers.
One S3 behaviour surprises people: a missing object returns 403 rather than 404 when the caller lacks s3:ListBucket, so S3 doesn't reveal which keys exist. Grant list permission if you want real 404s.
Azure Blob Storage
The most common Azure trap is mixing up control-plane and data-plane roles. An AuthorizationPermissionMismatch error means the identity is authenticated but lacks a data-plane role: Owner or Contributor on the subscription isn't enough, and you need Storage Blob Data Reader or Storage Blob Data Contributor. AuthorizationFailure usually means the storage firewall, a virtual network rule or disabled public access is blocking your IP. A signature mismatch points to an expired or malformed SAS token, or clock skew on the client.
API keys and third-party APIs
With API keys, a missing key usually gets a 401, while a valid key without access to that endpoint or plan gets a 403. Keys may also be restricted by IP, referrer or app, so calls from anywhere else are refused. Many APIs reject requests that have no User-Agent header. And some, GitHub among them, can return 403 when you exceed rate limits, so read the response body and headers before you assume a permissions problem.
A checklist for any 403
When the cause isn't obvious, walk the request through each layer:
- Reproduce it with curl to remove browser noise, with and without cookies or an
Authorization header. - Read the response body and headers. A
Server, cf-ray or x-amz-request-id header tells you whether the CDN, the web server or the app produced the 403. - Check the logs at each layer: CDN or WAF events, the web server error log, application logs.
- Confirm identity by decoding the token and listing the claims, roles and scopes the server actually received.
- Find the role, policy, IAM statement or ACL the request needs, and check this identity has it.
- Check the file system: ownership, permissions on every parent directory, the SELinux context, NTFS rights for the app pool.
- Check network rules: IP allow and deny lists, VPNs, country blocks, storage firewalls.
- If the URL is a directory, check there's an index or default document.
- Change one thing at a time and retest, so you know which change fixed it.
# Who answered? Look at status, Server, and any cf-ray / x-amz-request-id headers
curl -sI https://example.com/admin/ | head -n 20
# Same request with a bearer token
curl -i -H "Authorization: Bearer $TOKEN" https://api.example.com/orders/42
Step 2 deserves the most attention. The easiest way to waste an afternoon on a 403 is to debug the wrong layer, such as changing file permissions when the CDN is refusing the request, and the response headers usually tell you which layer to look at.
Join the conversation! Your thoughts help the community grow.