All ArticlesSecurity2026-11-16T08:39:26+08:00

Login Failures Show 200 OK Instead of 401? Your Auth Endpoint Leaks ATO Success Signals

Your application returns 200 OK for both failed and successful logins, making it impossible to distinguish credential stuffing successes from failures in access logs. After reading, you will know how to use response status codes and body_bytes_sent differences to reliably flag account takeover in Nginx or Apache logs.

Most people assume their web server access logs will clearly show when a login attempt fails versus when it succeeds. Failed login? That should be a 401. Successful login? A 200 or 302. Grep for one, count the other, done. Except a large number of web applications — including many built on popular frameworks — return HTTP 200 OK for both outcomes. The actual success or failure lives inside the JSON body ({"success": false}), invisible to anything reading standard access logs.

This is not a theoretical problem. It means your access logs cannot distinguish a credential stuffing attack that failed entirely from one that compromised fifty accounts.

Why Applications Return 200 for Everything

The pattern typically comes from treating the login endpoint as an API call rather than a traditional form submission. The HTTP request was received, the server processed it, and it returned a response. From the transport layer's perspective, everything went fine — hence 200 OK. The application communicates success or failure through the response body, usually JSON.

Developers sometimes defend this deliberately. The argument: HTTP status codes describe the transport, not business logic. A failed login is not a server error or a missing resource, so 200 is "correct." Others do it unintentionally — their framework's default response helper sends 200 unless told otherwise.

Both camps create the same operational problem. Your Nginx or Apache access log records the status code and the response size. It does not parse JSON bodies. When every login attempt — valid or not — produces a 200 in the log, your monitoring dashboards show a 0% error rate even during an active attack.

What Credential Stuffing Looks Like When Everything Is 200

Modern credential stuffing does not come from one IP hammering your login page. Attackers distribute requests across thousands of residential proxies. Each IP sends one or two requests, then disappears. Rate limiting per IP catches nothing because no single IP exceeds any threshold.

The only reliable signal left in access logs is the outcome of each login attempt. In a typical stuffing attack using a list of stolen credentials from another breach, the vast majority of attempts fail. A small percentage succeed. If your logs can separate the two, you can spot the attack: a sudden spike in failed logins across many IPs, all hitting the same path, with a handful of successes mixed in.

But when every response is 200 OK, that separation vanishes. You see a bunch of POST requests to /api/login or /wp-login.php, all returning 200. No anomaly. No alert. The attacker who guessed three valid passwords looks identical to three legitimate users logging in.

For more on detecting the distributed pattern itself, see Credential Stuffing Rotates IP Every Request — Schedule Weekly Combo List Checks in Your Logs.

The body_bytes_sent Workaround

If you cannot change the application code immediately, there is a partial workaround: the response body size. A failed login response and a successful login response almost always differ in size. The failed response might be a short JSON error message. The successful response typically includes a session token, user profile data, redirect instructions, or a Set-Cookie header — making it noticeably larger (or sometimes smaller, if the failure response includes a verbose error page).

In Nginx, the variable $body_bytes_sent is part of the default combined log format. In Apache, %B (or %b) records the response size in bytes. Both are already in your logs if you have not changed the default format.

You can scan for login requests where the response size deviates from the typical failure size. Here is a rough approach using awk against an Nginx access log in combined format:

# Extract POST requests to /login path, show IP, status, and body bytes
# Adjust field positions (1,7, 9,10) based on your actual log format
awk '6 ~ /POST/ &&7 ~ /\\/login/ {print 1,9, $10}' /var/log/nginx/access.log | sort -k3 -n

Sample output format:

203.0.113.42 200 147
198.51.100.8 200 147
192.0.2.17  200 147
203.0.113.99 200 891
198.51.100.3 200 147

In this illustrative example, most responses are 147 bytes (failed logins returning a short error JSON). One response is 891 bytes — likely a successful login returning session data. That IP (203.0.113.99) and the associated account deserve immediate investigation.

This is not foolproof. Response sizes can vary for legitimate reasons (different error messages, localization, CSRF tokens of varying length). But as a triage signal during an active attack, it narrows the search dramatically compared to staring at a wall of 200 OK.

Fix the Root Cause: Return Proper Status Codes

The body_bytes_sent trick is a workaround. The real fix is making your application return appropriate HTTP status codes:

  • 401 Unauthorized — invalid credentials. RFC 9110 defines this as "the request lacks valid authentication credentials." This is the correct status for a wrong username or password.
  • 429 Too Many Requests — the user or IP has exceeded your rate limit for login attempts.
  • 200 OK or 302 Found — authentication succeeded.

With these in place, detecting credential stuffing from access logs becomes straightforward: a burst of 401s across many IPs targeting the login path, with occasional 200s or 302s indicating compromised accounts.

How you implement this depends on your stack. In a Node/Express app, it might be as simple as changing res.json({error: 'Invalid credentials'}) to res.status(401).json({error: 'Invalid credentials'}). In PHP, http_response_code(401) before your JSON output. In Django, returning HttpResponse(status=401) or using the REST framework's authentication classes which handle this by default.

One concern developers raise: "Won't returning 401 leak information about whether a username exists?" No — you return 401 for both invalid usernames and wrong passwords, with the same generic message. The status code tells the client (and your logs) that authentication failed. It does not tell anyone why.

Building a Log-Based Detection Rule

Once your application returns proper status codes, you can build simple detection logic. The pattern to watch for:

  1. High volume of 401 responses on the login path within a short window.
  2. Requests spread across many distinct source IPs (not a single brute-force source).
  3. A small number of 200/302 responses on the same path in the same window — these are the potential account takeovers.

Here is a quick way to get a count of status codes per hour for your login endpoint from Nginx logs:

# Count status codes for POST /login grouped by hour
# Assumes standard combined log format with date in field $4
awk '6 ~ /POST/ &&7 ~ /\\/login/ {split(4,a,":"); print a[2]":00",9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn

Sample output format:

  847 14:00 401
   12 14:00 200
    3 14:00 429
   45 13:00 401
    8 13:00 200

In this illustrative example, the 14:00 hour shows a sharp spike in 401s with 12 successes — worth investigating whether those 12 accounts were compromised. The 13:00 hour looks like normal traffic.

For environments already using centralized logging (ELK, Loki, Splunk, or similar), the same logic translates into queries filtering on request path, method, and status code. The key point is that none of this works if every response is 200.

What About Existing Logs Where Everything Is Already 200

If you suspect a past credential stuffing attack but your logs only show 200 for the login endpoint, the body_bytes_sent analysis described earlier is your best option for retroactive triage. Group login requests by response size, identify the outlier sizes, and cross-reference those IPs and timestamps with your application's own authentication logs (if any exist — database records of last login time, session creation logs, audit tables).

This is also a good argument for application-level auth logging separate from access logs. Even if your HTTP status codes are all 200, an application log line that records auth_result=success user=jane.doe or auth_result=failure user=jane.doe gives you what the access log cannot.

Practical Takeaway

Return 401 for failed logins. Return 200 or 302 for successful ones. This is not pedantic REST purism — it is the difference between your access logs being a useful security tool and being a wall of identical lines during an active account takeover. If you cannot change the application code today, start analyzing body_bytes_sent differences on your login path to separate successes from failures. And if you are evaluating a new application or framework, check what status code the login endpoint returns on failure before it reaches production. A five-second curl test now saves hours of forensic guesswork later.