AC-035 Scenario not caught

Authentication error codes are mixed up

Behaviour a schema cannot see

How to run this card's commands yourself

1. The problem

In one sentence

A failed login or a missing token is answered with 200 OK and an error body, instead of 401 Unauthorized.

A story

A client sends a wrong password to POST /login. The spec says the answer is 401. The server answers 200 OK with {"error": "invalid credentials"}. The team’s own client reads the error field, so it works. Everything else does not: the rate limiter sees a successful request, the circuit breaker stays closed, and the monitoring shows no failed logins during a password-guessing attack.

Why it hurts

Authentication errors are the most important errors to see. A 200 hides them from every tool that watches statuses.

  • For developers: clients must check the body of every answer to learn whether a login worked. The cause is often a framework handler that “handles” auth errors by returning a uniform success envelope.
  • For managers: this is a security-monitoring gap. Brute-force attempts and stolen-token use look like normal traffic. Auditors and incident reviewers rely on those statuses.
  • For DevOps: rate limiting, lockout and alerting all key on 401 and 403. With 200, none of them fires.

Example

The spec declares 401 for a wrong password and for a missing token. The broken server answers:

POST /login {"username":"alice","password":"wrong"}  ->  200  {"error":"invalid credentials"}     (should be 401)
GET  /profile  (no token)                            ->  200  an error body                       (should be 401)

How to detect it without clrsig

  • curl -s -o /dev/null -w '%{http_code}\n' -d '{"username":"alice","password":"wrong"}' URL/login and compare with the spec.
  • In the access logs, count the failed logins: if they show as 200, the monitoring cannot see them.

How to fix it

There are two usual causes:

  1. The code is wrong (almost always). Answer 401 for missing or invalid credentials and 403 when the caller is known but not allowed. Keep the body for the explanation.
  2. The spec is wrong. Only if the API is documented to use a success envelope. That design hides failures from the platform, so it should be changed too.

To tell which: read the spec. If it declares 401, the code is wrong. Never reply 200 to a failed login.

AC-031 A request without credentials is accepted, AC-032 Wrong, expired or under-privileged credentials are accepted, AC-034 The wrong HTTP status for a business error. Failure-catalog demo: FM-025-02. See also the site’s Incorrect HTTP Status and Business-Error Semantics.

Words used on this page are explained once in the glossary.

2. How clrsig helps

Check

No built-in check for the status here, and the state is not caught. A scenario that asserts 401 finds it. In this demo the scenario also names the spec (specFile), so the body is compared with the shape of a successful login too, which adds a second finding.

Command

This demo is a runnable server in the failure catalog. Its first step sends a POST to its own local toy server:

Safety. Run this against a test server, never production. clrsig conform sends POST, PUT and DELETE requests built from the spec: start with --read-only, and take secrets from the environment (${NAME}), never from files in the repository.

cd failures/fm-025-02-auth-error-code
go run broken/main.go &
clrsig run scenarios/detect.yaml --env environments/local.yaml

Exit code: 0 all steps pass, 1 a step failed, 2 the scenario or the setup is broken. Here it is 1. Against fixed/main.go both steps pass and the exit code is 0.

What you see

Output from clrsig v0.21.0, recorded on 2026-11-30:

Scenario: fm-025-02 — Authentication Error Code Confusion

  FAIL  POST /login with wrong password — must return 401, not 200  200  16ms
         ✗ status eq 401: expected "401"; got "200"
         ✗ schema: Error at "/token": property "token" is missing
         → [CS-RESP-005] "token" is missing from the response. Why: The spec marks "token" as required, but the server's response did not include it. Where: response body, field token. Fix: Return "token" from the server, or make it optional in the spec if it is not always present.
  SKIP  GET /profile without token — must return 401, not 200
         skipped: step 1 (POST /login with wrong password — must return 401, not 200) failed and its failPolicy is stop; set failPolicy: continue to run the steps after a failure

FAILED  0 passed, 1 failed, 1 skipped  (0/2 assertions passed)  17ms

How to read it: two findings on the first step. The status is 200 and not 401. And the body has no token, the sign that this answer is an error, not a login. The failed schema check carries its check ID, CS-RESP-005, with why and fix.

Where to look

  • Desktop app: open the scenario and run it; the failed step shows both findings.
  • Reports: --format json and junit on clrsig run.
  • GitHub Action: use command: run with the scenario and env inputs. The demo’s scenario names its spec with specFile, so responses are compared with it. To compare your own responses with your spec, name it with specFile in the scenario, or give the spec input, which replaces it; older releases of the Action ignored that input with run (setup and upgrading).

How clrsig helps you fix it

It shows the status and the body together. It cannot see your monitoring or your rate limiter, so check those after the fix.

Limits

  • The second step (a profile call without a token) is skipped, and the output says why: step 1 failed and its failPolicy is stop. Set failPolicy: continue to run it.
  • Only the cases you write are tested, for example a wrong password and a missing token. Add expired and under-privileged tokens as separate steps (AC-032).

More ways

Nothing yet.

3. Video brief for Google NotebookLM

VIDEO BRIEF — AC-035 · Authentication error codes are mixed up
Length: 5 to 7 minutes. Language: English. Audience: developers, with a line each for managers and DevOps.
One idea: a failed login must be a 401, because rate limiters, lockouts and alerts all watch the status; a 200 hides the attack.
Open with this story: A client sends a wrong password to the login route. The spec says the answer is 401. The server answers 200 OK with a body that says invalid credentials. The team's own client reads the error field, so it works. Everything else does not: the rate limiter sees a successful request, the circuit breaker stays closed, and the monitoring shows no failed logins during a password-guessing attack.
Say these facts, in this order:
1. The spec declares 401 for a wrong password and a missing token. The broken server answers 200 for both.
2. The scenario asserts 401. The first step fails: expected 401, got 200.
3. The scenario also names the spec, so a second finding appears: the body has no token, the sign that this is an error and not a login.
4. Authentication errors are the most important errors to see; a 200 hides them from every tool that watches statuses.
5. Two usual causes: the code is wrong (answer 401 for missing or invalid credentials, 403 when the caller is known but not allowed), or the API is documented with a success envelope, which hides failures from the platform.
6. For managers: a security-monitoring gap; brute force and stolen-token use look like normal traffic.
7. For DevOps: rate limiting, lockout and alerting key on 401 and 403.
Show on screen: the two example lines, the commands (go run broken/main.go and clrsig run scenarios/detect.yaml --env environments/local.yaml), and the output block, copied exactly from the card.
Name the check: none built in; found by a status assertion and the spec binding in a scenario. Say the clrsig version: v0.21.0.
Explain these words once: 401 (not authenticated); 403 (authenticated but not allowed); rate limiter (a guard that slows down callers who send too many requests); scenario (a script of steps with your own checks, called assertions); exit code (0 clean, 1 a finding, 2 setup or spec broken).
Say what clrsig does not see here: your monitoring and rate limiter; the second step is skipped after a failure when the fail policy is stop, and the output says why; only the cases you write are tested.
Safety line (if a write is shown): Run this against a test server, never production. clrsig conform sends POST, PUT and DELETE requests built from the spec: start with --read-only, and take secrets from the environment (${NAME}), never from files in the repository.
Finish with three recap questions:
1. Which status should a wrong password answer? (401.)
2. Why does a 200 hide an attack? (Rate limiters and alerts watch the status.)
3. Which status means known but not allowed? (403.)
Tease the next video: AC-036 · The pagination contract is broken.
Do not: say "contract testing" alone; say clrsig "catches everything"; invent flags, IDs or numbers; read tables aloud; use any fact that is not in the card.