mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
fix(auth): stop counting credential-less requests as failed logins
After a server restart every cookie session is gone (they live in memory). An open tab's background requests then carry only the dead cookie and no Authorization header. Each one was counted as a failed login: ten filled the single-user per-IP bucket within seconds, and the 429 that followed carries no WWW-Authenticate challenge, so the browser never showed its login dialog again and reloading could not recover for 15 minutes. Behind a tunnel all clients share 127.0.0.1, so every device was locked out. Multi-user mode had the same shape against its per-IP pre-gate, which refuses even a correct password once full. A request with no Authorization header is not a guess and runs no password check, so it is now challenged with a plain 401 and not counted, in both modes and even while the IP is limited. Wrong and malformed credentials are counted and limited exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e99b42c387
commit
363de086fc
3 files changed
+76
-4
No files matched your search
@@ -244,6 +244,34 @@ describe('Auth Security', () => {
|
||||
|
||||
expect(wrongAfterRecovery.status).toBe(401);
|
||||
});
|
||||
|
||||
it('should not count requests without credentials (restart with a tab open)', async () => {
|
||||
// After a restart the open tab's background requests carry only a dead cookie.
|
||||
for (let i = 0; i < AUTH_FAILURE_MAX * 3; i++) {
|
||||
const res = await fetch(`${rateBaseUrl}/api/status`, {
|
||||
headers: { Cookie: 'codeman_session=stale-from-before-restart' },
|
||||
});
|
||||
expect(res.status).toBe(401);
|
||||
expect(res.headers.get('www-authenticate')).toBe('Basic realm="Codeman"');
|
||||
}
|
||||
|
||||
// None of them were guesses: the wrong-password bucket is still empty.
|
||||
await exhaustAuthFailures(rateBaseUrl, 'cod-no-creds');
|
||||
});
|
||||
|
||||
it('should keep challenging requests without credentials during lockout', async () => {
|
||||
await exhaustAuthFailures(rateBaseUrl, 'cod-challenge');
|
||||
|
||||
// A 429 never makes a browser show its login dialog; a 401 challenge does.
|
||||
const res = await fetch(`${rateBaseUrl}/api/status`);
|
||||
expect(res.status).toBe(401);
|
||||
expect(res.headers.get('www-authenticate')).toBe('Basic realm="Codeman"');
|
||||
|
||||
const wrong = await fetch(`${rateBaseUrl}/api/status`, {
|
||||
headers: { Authorization: basicAuthHeader(TEST_USER, 'still-wrong') },
|
||||
});
|
||||
expect(wrong.status).toBe(429);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Hook Event Endpoint', () => {
|
||||
|
||||
Reference in new issue
Block a user