🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(project): validate route-safe slugs (#18407)
Arvin Xu431858f439e5
diff --git a/apps/server/src/routers/lambda/__tests__/integration/project.integration.test.ts b/apps/server/src/routers/lambda/__tests__/integration/project.integration.test.tsindex 3a8d675a1a9..55f067ee336 100644--- a/apps/server/src/routers/lambda/__tests__/integration/project.integration.test.ts+++ b/apps/server/src/routers/lambda/__tests__/integration/project.integration.test.ts@@ -93,4 +93,40 @@ describe('Project Router Integration', () => {'Invalid project identifier',);});++ it.each(['team/launch', 'roadmap?draft', '#plan', 'two--hyphens'])(+ 'rejects the route-unsafe slug %s when creating a project',+ async (slug) => {+ await expect(+ caller.create({ identifier: 'VALID', name: 'Invalid slug', slug }),+ ).rejects.toThrow('Invalid project slug');+ },+ );++ it.each(['team/launch', 'roadmap?draft', '#plan', 'two--hyphens'])(+ 'rejects the route-unsafe slug %s when updating a project',+ async (slug) => {+ const project = await caller.create({+ identifier: 'VALID',+ name: 'Valid project',+ slug: 'valid-project',+ });++ await expect(caller.update({ id: project.data.id, slug })).rejects.toThrow(+ 'Invalid project slug',+ );+ },+ );++ it('accepts underscores in project slugs', async () => {+ const project = await caller.create({+ identifier: 'VALID',+ name: 'Valid project',+ slug: 'team_launch',+ });+ expect(project.data.slug).toBe('team_launch');++ const updated = await caller.update({ id: project.data.id, slug: 'team_launch_v2' });+ expect(updated.data.slug).toBe('team_launch_v2');+ });});diff --git a/apps/server/src/routers/lambda/project.ts b/apps/server/src/routers/lambda/project.tsindex 349c6cee4f3..c5f0c1c9428 100644--- a/apps/server/src/routers/lambda/project.ts+++ b/apps/server/src/routers/lambda/project.ts@@ -19,11 +19,13 @@ const projectProcedure = wsCompatProcedure.use(serverDatabase).use(async (opts)const projectWriteProcedure = projectProcedure.use(withScopedPermission('agent:update'));const idInput = z.object({ id: z.string() });+const PROJECT_SLUG_REGEX = /^[a-z0-9]+(?:[-_][a-z0-9]+)*$/;const projectIdentifierInput = z.string().trim().transform((value) => value.toUpperCase()).pipe(z.string().regex(PROJECT_IDENTIFIER_REGEX, 'Invalid project identifier'));+const projectSlugInput = z.string().max(100).regex(PROJECT_SLUG_REGEX, 'Invalid project slug');function requireResult<T>(result: T | null, message = 'Project not found'): T {if (!result) throw new TRPCError({ code: 'NOT_FOUND', message });@@ -103,7 +105,7 @@ export const projectRouter = router({description: z.string().optional(),identifier: projectIdentifierInput,name: z.string().min(1).max(255),- slug: z.string().max(100).optional(),+ slug: projectSlugInput.optional(),visibility: z.enum(PROJECT_VISIBILITIES).optional(),}),)@@ -268,7 +270,7 @@ export const projectRouter = router({avatar: z.string().nullish(),description: z.string().nullish(),name: z.string().min(1).max(255).optional(),- slug: z.string().max(100).nullish(),+ slug: projectSlugInput.nullish(),visibility: z.enum(PROJECT_VISIBILITIES).optional(),}),)