mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
fix(server): bound every outbound fetch
The rule is a timeout, a size cap and boundary validation on anything that leaves the process, and several call sites had only the timeout. A link preview, a maps URL resolve, a wiki fallback and a holiday lookup all read the whole body into memory, so a caller who picks the URL picks how much memory the server spends - a few concurrent multi-hundred-megabyte responses is the whole heap. Two of them also fetched more than their name suggests. resolve-url fell through to a full page GET for any host once it found no coordinates, which makes the server a general-purpose outbound proxy wearing its own IP. The weather URLs took lat/lng straight from the caller into the query string. readCapped/exceedsDeclaredLength collect the pattern transit.service.ts and the plugin installer had each grown separately, so there is one of it now. Callers that only scan the head of a document (og: tags, a coordinate regex) keep the truncated bytes and find fewer fields; callers that must have the whole thing reject it.
This commit is contained in:
@@ -395,6 +395,31 @@ describe('getGithubReleases', () => {
|
||||
expect(result).toHaveLength(2);
|
||||
expect((result as any[])[0].tag_name).toBe('v3.0.0');
|
||||
});
|
||||
|
||||
it('ADMIN-SVC-053a — clamps the paging query instead of interpolating it raw', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({ ok: true, text: async () => '[]' });
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await getGithubReleases('9999', '0');
|
||||
expect(fetchMock.mock.calls[0][0]).toBe(
|
||||
'https://api.github.com/repos/liketrek/TREK/releases?per_page=100&page=1',
|
||||
);
|
||||
|
||||
await getGithubReleases('10&per_page=999', 'abc');
|
||||
expect(fetchMock.mock.calls[1][0]).toBe(
|
||||
'https://api.github.com/repos/liketrek/TREK/releases?per_page=10&page=1',
|
||||
);
|
||||
});
|
||||
|
||||
it('ADMIN-SVC-053b — round-trips the paging the admin UI actually sends', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({ ok: true, text: async () => '[]' });
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await getGithubReleases('20', '2');
|
||||
expect(fetchMock.mock.calls[0][0]).toBe(
|
||||
'https://api.github.com/repos/liketrek/TREK/releases?per_page=20&page=2',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ── checkVersion ──────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user