test(auth): pin the hook's 403 for the two dead web-tab requests

Under a dead web-tab capability, GET /webview/<cap> without the trailing
slash and a WebSocket upgrade have no route status to copy (the route
alone redirects, or accepts and closes with 4003). With trusted-proxy
sign-in on, the hook answers both with 403, no challenge and no count.
The refusal test sends each of them more often than the per-IP failure
limit, before its final Basic sign-in, so a counted one turns that
sign-in into a 429.
This commit is contained in:
13768039+zomby1 committed 2026-11-26 18:34:40 +01:00
1 parent dcfa76125f
commit 992819ba98
1 file changed
+38 -2
+38 -2
View File
@@ -21,7 +21,7 @@ import WebSocket from 'ws';
import { WebServer } from '../src/web/server.js';
import { TmuxManager } from '../src/tmux-manager.js';
import { createUser, invalidateUsersCache, touchLastLogin, updateUser } from '../src/user-store.js';
import { AUTH_FAILURE_MAX } from '../src/config/auth-config.js';
import { AUTH_FAILURE_MAX, AUTH_IP_FAILURE_MAX } from '../src/config/auth-config.js';
import {
getTrustedProxyConfig,
initTrustedProxySecret,
@@ -832,7 +832,43 @@ describe('trusted-proxy sign-in', () => {
expect(res.statusCode, url).toBe(status);
expect(res.headers['www-authenticate'], url).toBeUndefined();
}
// 60 such requests did not fill the per-IP bucket: Basic from loopback still works.
// Two requests with no route status to copy get the hook's 403 too. Without the slash
// the route alone would redirect (302); an upgrade it would accept and close with 4003.
// Each is sent more often than the per-IP failure limit, so a counted one would turn the
// final sign-in below into a 429.
const deadCap = 'Z'.repeat(32);
const upgradeHeaders = {
connection: 'Upgrade',
upgrade: 'websocket',
'sec-websocket-version': '13',
'sec-websocket-key': 'dGhlIHNhbXBsZSBub25jZQ==',
};
for (let i = 0; i < AUTH_IP_FAILURE_MAX + 10; i++) {
const headers: Record<string, string> = { host: 'localhost' };
if (i % 2) headers.authorization = basic('bob', 'wrong-password');
const noSlash = await app.inject({
method: 'GET',
url: `/webview/${deadCap}`,
remoteAddress: '127.0.0.1',
headers,
});
expect(noSlash.statusCode).toBe(403);
expect(noSlash.headers['www-authenticate']).toBeUndefined();
expect(noSlash.headers.location).toBeUndefined();
}
for (let i = 0; i < AUTH_IP_FAILURE_MAX + 10; i++) {
const headers: Record<string, string> = { host: 'localhost', ...upgradeHeaders };
if (i % 2) headers.authorization = basic('bob', 'wrong-password');
const upgrade = await app.inject({
method: 'GET',
url: `/webview/${deadCap}/socket`,
remoteAddress: '127.0.0.1',
headers,
});
expect(upgrade.statusCode).toBe(403);
expect(upgrade.headers['www-authenticate']).toBeUndefined();
}
// None of these requests filled the per-IP bucket: Basic from loopback still works.
expect((await injectMe(app, '127.0.0.1', { authorization: basic('bob', 'bobpass123') })).statusCode).toBe(200);
});