Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: reject repeated message inbox query fields with a 400 before reading caches (#13150)

Adam Eivy84454dd2e51d
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 95d1bfa63d..0248a67eec 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -2062,6 +2062,16 @@ export function parsePagination(query, { defaultLimit = 50, maxLimit = 200 } = {
return { limit, offset };
}
+// Express turns a repeated `?k=a&k=b` into an array; each field must be scalar
+// before any cache read (#13150). Pagination stays lenient via parsePagination.
+export const messageInboxQuerySchema = z.object({
+ accountId: z.string().optional(),
+ search: z.string().optional(),
+ summary: z.string().optional(),
+ limit: z.string().optional(),
+ offset: z.string().optional()
+});
+
/**
* Did the caller explicitly ask for pagination? True when either `limit` or
* `offset` is present in the query string. Lets a list endpoint stay
diff --git a/server/routes/messageInboxRead.js b/server/routes/messageInboxRead.js
index c89f216be7..50838cd21e 100644
--- a/server/routes/messageInboxRead.js
+++ b/server/routes/messageInboxRead.js
@@ -1,20 +1,21 @@
// Shared production inbox route, without sync, send, browser or AI endpoints.
import { z } from 'zod';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
-import { parsePagination } from '../lib/validation.js';
+import { messageInboxQuerySchema, parsePagination, validateRequest } from '../lib/validation.js';
import { UUID_RE } from '../lib/fileUtils.js';
import * as messageSync from '../services/messageSync.js';
export const messageInboxRead = asyncHandler(async (req, res) => {
- const { accountId, search } = req.query;
+ const query = validateRequest(messageInboxQuerySchema, req.query);
+ const { accountId, search } = query;
if (accountId && !UUID_RE.test(accountId)) {
throw new ServerError('Invalid accountId format', { status: 400 });
}
- const { limit: parsedLimit, offset: parsedOffset } = parsePagination(req.query, { defaultLimit: 50, maxLimit: 100 });
+ const { limit: parsedLimit, offset: parsedOffset } = parsePagination(query, { defaultLimit: 50, maxLimit: 100 });
const result = await messageSync.getMessages({
accountId,
search,
- summary: req.query.summary === 'true',
+ summary: query.summary === 'true',
limit: parsedLimit,
offset: parsedOffset
});
diff --git a/server/routes/messageInboxRead.test.js b/server/routes/messageInboxRead.test.js
index 4f7484f618..701a643a73 100644
--- a/server/routes/messageInboxRead.test.js
+++ b/server/routes/messageInboxRead.test.js
@@ -130,6 +130,21 @@ describe('inbox summary reads through the production HTTP/service boundary', ()
expect(tryReadFile).toHaveBeenCalledTimes(3);
});
+ it('rejects repeated query fields as a validation error before reading any cache', async () => {
+ await seed(1);
+ const repeated = [
+ 'search=first&search=second',
+ `accountId=${ACCOUNT_IDS[0]}&accountId=${ACCOUNT_IDS[1]}`,
+ 'summary=true&summary=false'
+ ];
+ for (const query of repeated) {
+ const response = await request(app).get('/inbox?' + query);
+ expect(response.status).toBe(400);
+ expect(response.body.code).toBe('VALIDATION_ERROR');
+ }
+ expect(tryReadFile).not.toHaveBeenCalled();
+ });
+
it('never serves old summaries after unreadable, corrupt, missing or empty caches', async () => {
const id = ACCOUNT_IDS[0];
const restore = () => writeFile(cachePath(id), JSON.stringify({ messages: [messageFixture(id, 1)] }));