test(auth): malformed headers still fill the bucket; document the challenge

Review on #838. The unchanged half had no test: send the cap's worth of
`Authorization: Bearer x` and expect the next request to be 429, in
single-user and multi-user mode. Both fail if the header-less skip is
widened to malformed headers.

docs/security-architecture.md gets a pipeline step for the header-less
challenge (not counted, even during a lockout), and the Rate limit rows in
CLAUDE.md and docs/architecture-invariants.md say so, so a later change
cannot bring the counting back unnoticed. auth.ts uses challengeBasicAuth()
at the two spots that still inlined it, with a blank comment line before
the new paragraph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kamil KaliszandClaude Opus 5.5 committed 2026-11-20 20:36:03 +01:00
1 parent 363de086fc
commit ad08cb957d
6 files changed
+46 -11

No files matched your search

+13
View File
@@ -291,6 +291,19 @@ describe('multi-user auth', () => {
expect((await login(ip, 'alice', 'alicepass1')).statusCode).toBe(200);
});
it('malformed authorization headers are still counted against the per-IP cap', async () => {
const { app } = await startIpServer();
const ip = '203.0.113.41';
const malformed = () =>
app.inject({ method: 'GET', url: '/api/status', headers: { authorization: 'Bearer x' }, remoteAddress: ip });
// Present but not valid Basic: a failed login, unlike a request with no header.
for (let i = 0; i < AUTH_IP_FAILURE_MAX; i++) {
expect((await malformed()).statusCode, `request ${i + 1}`).toBe(401);
}
expect((await malformed()).statusCode).toBe(429);
});
it('per-IP pre-gate: a concurrent burst from one IP reaches the verify at most AUTH_IP_FAILURE_MAX times', async () => {
const { login, buckets } = await startIpServer();
const ip = '203.0.113.40';