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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: disallow reserved route slugs in tool registration (#9608)
Adam Eivy12144393ec06
diff --git a/server/routes/tools.js b/server/routes/tools.jsindex fa3bbfa0d5..68003d6a88 100644--- a/server/routes/tools.js+++ b/server/routes/tools.js@@ -12,7 +12,19 @@ import * as toolsService from '../services/tools.js';const router = Router();-const toolIdSchema = z.string().min(1).max(100).regex(/^[a-zA-Z0-9_-]+$/, 'Tool ID must contain only alphanumeric characters, hyphens, and underscores');+// Reserved subpaths that would shadow the parameterized /:id route+const RESERVED_TOOL_IDS = ['enabled', 'summary'];++const toolIdSchema = z.string()+ .min(1)+ .max(100)+ .regex(/^[a-zA-Z0-9_-]+$/, 'Tool ID must contain only alphanumeric characters, hyphens, and underscores')+ .refine(+ (id) => !RESERVED_TOOL_IDS.includes(id),+ (ctx) => ({+ message: `Tool ID cannot be a reserved route slug (${RESERVED_TOOL_IDS.join(', ')})`+ })+ );const registerToolSchema = z.object({id: toolIdSchema.optional(),diff --git a/server/routes/tools.test.js b/server/routes/tools.test.jsindex 5064a555ea..daaa1ff6b3 100644--- a/server/routes/tools.test.js+++ b/server/routes/tools.test.js@@ -135,6 +135,58 @@ describe('Tools Routes', () => {expect(response.status).toBe(400);expect(toolsService.registerTool).not.toHaveBeenCalled();});++ it('should reject reserved route slug "enabled"', async () => {+ const response = await request(app)+ .post('/api/tools')+ .send({ id: 'enabled', name: 'Bad Tool', category: 'test' });++ expect(response.status).toBe(400);+ expect(response.body.code).toBe('VALIDATION_ERROR');+ expect(toolsService.registerTool).not.toHaveBeenCalled();+ });++ it('should reject reserved route slug "summary"', async () => {+ const response = await request(app)+ .post('/api/tools')+ .send({ id: 'summary', name: 'Bad Tool', category: 'test' });++ expect(response.status).toBe(400);+ expect(response.body.code).toBe('VALIDATION_ERROR');+ expect(toolsService.registerTool).not.toHaveBeenCalled();+ });++ it('should accept valid custom IDs that are not reserved', async () => {+ const toolData = {+ id: 'my-tool',+ name: 'My Tool',+ category: 'custom',+ description: 'A custom tool'+ };+ toolsService.registerTool.mockResolvedValue({ ...toolData, createdAt: '2026-01-01' });++ const response = await request(app)+ .post('/api/tools')+ .send(toolData);++ expect(response.status).toBe(201);+ expect(toolsService.registerTool).toHaveBeenCalledWith(expect.objectContaining({ id: 'my-tool' }));+ });++ it('should accept tools with auto-generated IDs', async () => {+ const toolData = {+ name: 'Auto Generated Tool',+ category: 'test'+ };+ toolsService.registerTool.mockResolvedValue({ ...toolData, id: 'auto-id-123', createdAt: '2026-01-01' });++ const response = await request(app)+ .post('/api/tools')+ .send(toolData);++ expect(response.status).toBe(201);+ expect(toolsService.registerTool).toHaveBeenCalledWith(expect.objectContaining(toolData));+ });});describe('PUT /api/tools/:id', () => {