7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(routes): sort-preset whitelist rejects inherited Object members (#1685)
tashdroid95a801b16c4d
diff --git a/server/src/__tests__/routes/fallback.test.ts b/server/src/__tests__/routes/fallback.test.tsindex e27d7a20..4223fff1 100644--- a/server/src/__tests__/routes/fallback.test.ts+++ b/server/src/__tests__/routes/fallback.test.ts@@ -459,4 +459,14 @@ describe('Fallback API', () => {const { status } = await request(app, 'POST', '/api/fallback/sort/invalid');expect(status).toBe(400);});++ it('POST /api/fallback/sort/constructor returns 400, not 500', async () => {+ // Inherited Object members (`constructor`, `toString`, …) are truthy, so+ // a bare `SORT_PRESETS[preset]` read used to pass the whitelist guard and+ // crash `prepare()` when the function object got interpolated into SQL.+ const { status } = await request(app, 'POST', '/api/fallback/sort/constructor');+ expect(status).toBe(400);+ const { status: tsStatus } = await request(app, 'POST', '/api/fallback/sort/toString');+ expect(tsStatus).toBe(400);+ });});diff --git a/server/src/routes/fallback.ts b/server/src/routes/fallback.tsindex a15caa94..bdbe9575 100644--- a/server/src/routes/fallback.ts+++ b/server/src/routes/fallback.ts@@ -423,7 +423,10 @@ fallbackRouter.post('/sort/:preset', (req: Request, res: Response) => {allModels.sort((a, b) => monthlyBudgetScore(b) - monthlyBudgetScore(a));models = allModels.map(m => ({ id: m.id }));} else {- const orderBy = SORT_PRESETS[preset];+ // `Object.hasOwn`, not a bare index: a plain read answers for inherited+ // members too, so `POST /sort/constructor` used to slip past this guard+ // (the function object is truthy) and crash `prepare()` with a 500.+ const orderBy = Object.hasOwn(SORT_PRESETS, preset) ? SORT_PRESETS[preset] : undefined;if (!orderBy) {res.status(400).json({ error: { message: `Unknown preset: ${preset}. Use: intelligence, speed, budget` } });return;diff --git a/server/src/routes/profiles.ts b/server/src/routes/profiles.tsindex 2bfb849b..ff5d8a9c 100644--- a/server/src/routes/profiles.ts+++ b/server/src/routes/profiles.ts@@ -394,7 +394,10 @@ function sortProfileModels(db: any, profileId: number, preset: string) {allModels.sort((a, b) => monthlyBudgetScore(b) - monthlyBudgetScore(a));models = allModels.map(m => ({ id: m.id }));} else {- const orderBy = SORT_PRESETS[preset];+ // `Object.hasOwn`, not a bare index: a plain read answers for inherited+ // members too, so `constructor`/`toString` used to slip past this guard+ // (the function object is truthy) and crash `prepare()` with a 500.+ const orderBy = Object.hasOwn(SORT_PRESETS, preset) ? SORT_PRESETS[preset] : undefined;if (!orderBy) {throw new Error(`Unknown preset: ${preset}. Use: intelligence, speed, budget`);}