fix(api): answer 403 when the client ip header is unparsable (#2483)

This commit is contained in:
Hampus authored and GitHub committed 2026-09-06 15:23:35 +02:00
1 parent a036d9a2e1
commit 9a229c1b73
5 files changed
+109 -17

No files matched your search

@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {AppErrorHandler} from '@fluxer/errors/src/domains/core/ErrorHandlers';
import {MissingClientIpError} from '@fluxer/ip_utils/src/ClientIp';
import {Hono} from 'hono';
import {describe, expect, it} from 'vitest';
@@ -125,4 +126,15 @@ describe('RequestClientIp', () => {
await app.request('http://localhost/v1/messages', {headers: {'x-forwarded-for': '203.0.113.10'}});
expect(seen).toEqual(['203.0.113.10', null, '203.0.113.10']);
});
it('a missing client ip surfaces as 403 FORBIDDEN through AppErrorHandler', async () => {
const app = new Hono<HonoEnv>();
app.get('/v1/messages', (ctx) => {
requireRequestClientIp(ctx);
return ctx.text('ok');
});
app.onError(AppErrorHandler);
const response = await app.request('http://localhost/v1/messages');
expect(response.status).toBe(403);
expect(await response.json()).toMatchObject({code: 'FORBIDDEN'});
});
});