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: validate Git branch deletion flags (#8266)
[._.]/ Adam Eivy9452e88c2ae1
diff --git a/server/lib/apiOperationContracts.js b/server/lib/apiOperationContracts.jsindex e7fcf8e86b..381faeba6f 100644--- a/server/lib/apiOperationContracts.js+++ b/server/lib/apiOperationContracts.js@@ -9,6 +9,7 @@ import { writersRoomWorksQuerySchema, writersRoomWorksResponseSchema } from './pimport { TTS_ENGINE_IDS } from './voiceEngines.js';import { cosToolCallSchema } from './cosToolContracts.js';import { agentContextMcpInboundSchema } from './agentContextValidation.js';+import { gitDeleteBranchBodySchema } from './validation.js';const jsonBody = (schema, required = true) => ({required,@@ -16,6 +17,16 @@ const jsonBody = (schema, required = true) => ({});export const API_OPERATION_CONTRACTS = Object.freeze({+ '/api/git/delete-branch': {+ post: {+ summary: 'Delete a Git branch locally, remotely, or both',+ requestBody: jsonBody(gitDeleteBranchBodySchema),+ responses: {+ 200: { description: 'Branch deletion result' },+ 400: { description: 'Invalid branch deletion request', 'x-portos-error-codes': ['VALIDATION_ERROR'] },+ },+ },+ },'/api/api-docs/openapi.json': {get: { summary: 'Read exposed OpenAPI document', responses: { 200: { description: 'OpenAPI 3.0.3 document for currently exposed external APIs' } } },},diff --git a/server/lib/validation.js b/server/lib/validation.jsindex 7df6bf5dd4..2e155333a9 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -1,6 +1,15 @@import { CREDENTIALS } from './credentialRegistry.js';import { DEFAULT_BACKUP_CRON } from './backupConfig.js';import { z } from 'zod';++export const gitDeleteBranchBodySchema = z.object({+ path: z.string().min(1),+ branch: z.string().min(1),+ local: z.boolean().default(false),+ remote: z.boolean().default(false),+}).refine(({ local, remote }) => local || remote, {+ message: 'at least one of local or remote must be true',+});import { ServerError } from './errorHandler.js';import { partialWithoutDefaults, emptyToUndefined, emptyToNull, optionalBooleanMap, presetProviderIdSchema, providerRefSchema } from './zodCompat.js';import { WORK_TRACKERS } from './workTracker.js';diff --git a/server/routes/git.js b/server/routes/git.jsindex e94eee714b..671ac93645 100644--- a/server/routes/git.js+++ b/server/routes/git.js@@ -8,7 +8,7 @@ import { getAgents } from '../services/cosAgentLifecycle.js';import { protectedAgentIds } from '../services/agentState.js';import { asyncHandler, ServerError } from '../lib/errorHandler.js';import { isWithinAllowedRoots, outsideAllowedRootsMessage } from '../lib/workspaceRoots.js';-import { validateRequest, submoduleStatusQuerySchema, submoduleUpdateSchema } from '../lib/validation.js';+import { validateRequest, submoduleStatusQuerySchema, submoduleUpdateSchema, gitDeleteBranchBodySchema } from '../lib/validation.js';/*** Assert that a caller-supplied workspace path exists, is a directory, and@@ -284,14 +284,8 @@ router.post('/cleanup-merged', asyncHandler(async (req, res) => {// POST /api/git/delete-branch - Delete a branch locally and/or remotelyrouter.post('/delete-branch', asyncHandler(async (req, res) => {- const { path, branch, local, remote } = req.body;+ const { path, branch, local, remote } = validateRequest(gitDeleteBranchBodySchema, req.body);assertAllowedWorkspace(path);- if (!branch) {- throw new ServerError('branch is required', { status: 400, code: 'VALIDATION_ERROR' });- }- if (!local && !remote) {- throw new ServerError('at least one of local or remote must be true', { status: 400, code: 'VALIDATION_ERROR' });- }const { excludeBranches } = await getAgentProtections();const result = await git.deleteBranch(path, branch, { local, remote, excludeBranches });res.json(result);diff --git a/server/routes/git.test.js b/server/routes/git.test.jsindex 735019cbac..48d7110282 100644--- a/server/routes/git.test.js+++ b/server/routes/git.test.js@@ -252,6 +252,31 @@ describe('git routes — active agent branch exclusion', () => {});describe('POST /api/git/delete-branch — active agent branches are excluded', () => {+ it.each([+ { local: 'false', remote: 'false' },+ { local: 1, remote: false },+ { local: false, remote: 1 },+ ])('rejects non-boolean deletion flags: %j', async (flags) => {+ const res = await request(makeApp()).post('/api/git/delete-branch')+ .send({ path: WORKSPACE, branch: 'feature/x', ...flags });+ expect(res.status).toBe(400);+ expect(res.body.code).toBe('VALIDATION_ERROR');+ expect(gitService.deleteBranch).not.toHaveBeenCalled();+ });++ it.each([+ { local: true, remote: false },+ { local: false, remote: true },+ { local: true, remote: true },+ ])('passes boolean deletion flags: %j', async (flags) => {+ const res = await request(makeApp()).post('/api/git/delete-branch')+ .send({ path: WORKSPACE, branch: 'feature/x', ...flags });+ expect(res.status).toBe(200);+ expect(gitService.deleteBranch).toHaveBeenCalledWith(+ WORKSPACE, 'feature/x', expect.objectContaining(flags)+ );+ });+it('passes the active agent branches as excludeBranches to deleteBranch', async () => {cosAgentLifecycleService.getAgents.mockResolvedValue([{ status: 'running', metadata: { worktreeBranch: 'feature/agent-active' } },