⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix(api): answer 400 instead of 500 when an unauthenticated route gets malformed input (#297)
Ahmad Othman Ammar Adi22a9b6b0d3fb
diff --git a/apps/api/src/modules/attachments/__tests__/integration/attachments.test.ts b/apps/api/src/modules/attachments/__tests__/integration/attachments.test.tsindex 88d2600a..585e62c9 100644--- a/apps/api/src/modules/attachments/__tests__/integration/attachments.test.ts+++ b/apps/api/src/modules/attachments/__tests__/integration/attachments.test.ts@@ -242,6 +242,13 @@ describe('attachments', () => {.raw.get();expect(res.status).toBe(404);});++ // The route is public, so a malformed id reaching Postgres would answer 500 with+ // the driver's message to an anonymous caller.+ it('returns 400 for a publicId that is not a uuid', async () => {+ const res = await api.attachments({ publicId: 'not-a-uuid' }).raw.get();+ expect(res.status).toBe(400);+ });});describe('import (url or base64)', () => {diff --git a/apps/api/src/modules/attachments/index.ts b/apps/api/src/modules/attachments/index.tsindex 63a94950..9e0b0fb7 100644--- a/apps/api/src/modules/attachments/index.ts+++ b/apps/api/src/modules/attachments/index.ts@@ -20,6 +20,7 @@ import {AttachmentListResponse,importAttachmentBody,issueParams,+ publicIdParams,rawAttachmentQuery,uploadAttachmentBody,} from './model';@@ -374,10 +375,11 @@ export const attachmentRoutes = new Elysia({return new Response(obj.body, { headers });},{+ params: publicIdParams,query: rawAttachmentQuery,// Public route: no 401/403. Returns a raw Response (bytes), so no typed 200- // body — Elysia cannot validate a raw Response. Only the 404 it can throw.- response: { ...errors(404) },+ // body — Elysia cannot validate a raw Response. Only the statuses it can throw.+ response: { ...errors(400, 404) },detail: { summary: 'Download or preview an attachment (public, no auth)' },},);diff --git a/apps/api/src/modules/attachments/model.ts b/apps/api/src/modules/attachments/model.tsindex 9a419bf6..60866843 100644--- a/apps/api/src/modules/attachments/model.ts+++ b/apps/api/src/modules/attachments/model.ts@@ -14,6 +14,10 @@ export const AttachmentListResponse = t.Array(AttachmentResponse);export const issueParams = t.Object({ issueId: t.Numeric() });+// The public id is a UUID column. Validating its format here turns a malformed id+// into a 400 instead of letting it reach Postgres and surface as a 500.+export const publicIdParams = t.Object({ publicId: t.String({ format: 'uuid' }) });+export const uploadAttachmentBody = t.Object({ file: t.File() });export const importAttachmentBody = t.Object({diff --git a/apps/api/src/modules/chat-attachments/__tests__/integration/chat-attachments.test.ts b/apps/api/src/modules/chat-attachments/__tests__/integration/chat-attachments.test.tsindex e87b03c4..e1df8aa4 100644--- a/apps/api/src/modules/chat-attachments/__tests__/integration/chat-attachments.test.ts+++ b/apps/api/src/modules/chat-attachments/__tests__/integration/chat-attachments.test.ts@@ -159,4 +159,11 @@ describe('chat attachments', () => {}).raw.get();expect(gone.status).toBe(404);});++ // The route is public, so a malformed id reaching Postgres would answer 500 with+ // the driver's message to an anonymous caller.+ it('returns 400 for a publicId that is not a uuid', async () => {+ const res = await api['chat-attachments']({ publicId: 'not-a-uuid' }).raw.get();+ expect(res.status).toBe(400);+ });});diff --git a/apps/api/src/modules/chat-attachments/index.ts b/apps/api/src/modules/chat-attachments/index.tsindex 1ec93d6a..f83d8a1c 100644--- a/apps/api/src/modules/chat-attachments/index.ts+++ b/apps/api/src/modules/chat-attachments/index.ts@@ -236,10 +236,11 @@ export const chatAttachmentRoutes = new Elysia({return new Response(obj.body, { headers });},{+ params: publicIdParams,query: rawAttachmentQuery,// Public route: no 401/403. Returns a raw Response (bytes), so no typed 200- // body — Elysia cannot validate a raw Response. Only the 404 it can throw.- response: { ...errors(404) },+ // body — Elysia cannot validate a raw Response. Only the statuses it can throw.+ response: { ...errors(400, 404) },detail: { summary: 'Download a chat attachment (public, no auth)' },},);diff --git a/apps/api/src/modules/chat-attachments/model.ts b/apps/api/src/modules/chat-attachments/model.tsindex dba9d926..a38e7c86 100644--- a/apps/api/src/modules/chat-attachments/model.ts+++ b/apps/api/src/modules/chat-attachments/model.ts@@ -1,9 +1,7 @@import { t } from 'elysia';export { projectKeyParams } from '../issues/model';-export { rawAttachmentQuery } from '../attachments/model';--export const publicIdParams = t.Object({ publicId: t.String() });+export { publicIdParams, rawAttachmentQuery } from '../attachments/model';// The upload carries its bytes as base64 rather than multipart, so the one route// serves the chat composer and MCP callers alike (a tool call is a JSON body).diff --git a/apps/api/src/modules/share/__tests__/integration/share.test.ts b/apps/api/src/modules/share/__tests__/integration/share.test.tsindex 8410a926..6611c51a 100644--- a/apps/api/src/modules/share/__tests__/integration/share.test.ts+++ b/apps/api/src/modules/share/__tests__/integration/share.test.ts@@ -177,6 +177,20 @@ describe('share', () => {expect(shared.data.issues.map((i: { id: number }) => i.id)).toContain(issueId);});+ // A view's filters are stored as an uninspected jsonb blob, so a condition can+ // reach the server-side engine without the values every value operator reads.+ it('serves a view whose filter condition carries no values', async () => {+ const { asOwner, viewId, token, issueId } = await sharedView();+ const patched = await asOwner+ .views({ viewId })+ .patch({ filters: { conditions: [{ field: 'status', op: 'is' }] } });+ expect(patched.status).toBe(200);++ const shared = await api.share.view({ token }).get();+ expect(shared.status).toBe(200);+ expect(shared.data.issues.map((i: { id: number }) => i.id)).toContain(issueId);+ });+it('opens an issue from a shared board under the same token', async () => {const { token, issueId } = await sharedView();const res = await api.share.view({ token }).issues({ issueId }).get();diff --git a/apps/api/src/modules/views/filters.ts b/apps/api/src/modules/views/filters.tsindex 095678de..9a20c401 100644--- a/apps/api/src/modules/views/filters.ts+++ b/apps/api/src/modules/views/filters.ts@@ -54,7 +54,7 @@ function parseCustomFieldKey(field: string): number | null {// need none), so a half-built condition does not hide everything.function isEffectiveCondition(cond: FilterCondition): boolean {if (cond.op === 'is_set' || cond.op === 'is_not_set') return true;- return cond.values.length > 0;+ return Array.isArray(cond.values) && cond.values.length > 0;}function toFilterSet(raw: unknown): FilterSet {