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 write-route bodies and reject option-shaped refs (#9154)
[._.]/ Adam Eivy8a3f6cf3e10d
diff --git a/server/lib/apiOperationContracts.js b/server/lib/apiOperationContracts.jsindex 0dc859138d..5aaebbdec2 100644--- a/server/lib/apiOperationContracts.js+++ b/server/lib/apiOperationContracts.js@@ -9,14 +9,48 @@ 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';+import {+ gitBranchBodySchema, gitBranchComparisonBodySchema, gitCommitBodySchema, gitCommitsBodySchema, gitDeleteBranchBodySchema,+ gitDiffBodySchema, gitOptionalBranchBodySchema, gitPathBodySchema, gitRemoteBranchesBodySchema, gitStageBodySchema,+} from './validation.js';const jsonBody = (schema, required = true) => ({required,content: { 'application/json': { schema: zodToOpenApiSchema(schema) } },});+const gitWriteOperation = (summary, schema) => ({+ post: {+ summary,+ requestBody: jsonBody(schema),+ responses: {+ 200: { description: 'Git operation result' },+ 400: { description: 'Invalid request body', 'x-portos-error-codes': ['VALIDATION_ERROR'] },+ },+ },+});+export const API_OPERATION_CONTRACTS = Object.freeze({+ '/api/git/status': gitWriteOperation('Read git status for a path', gitPathBodySchema),+ '/api/git/diff': gitWriteOperation('Read the working-tree or staged diff', gitDiffBodySchema),+ '/api/git/commits': gitWriteOperation('List recent commits', gitCommitsBodySchema),+ '/api/git/stage': gitWriteOperation('Stage files', gitStageBodySchema),+ '/api/git/unstage': gitWriteOperation('Unstage files', gitStageBodySchema),+ '/api/git/commit': gitWriteOperation('Create a commit', gitCommitBodySchema),+ '/api/git/update-branches': gitWriteOperation('Fetch and merge the latest dev and main', gitPathBodySchema),+ '/api/git/branch-comparison': gitWriteOperation('Compare two branches', gitBranchComparisonBodySchema),+ '/api/git/push': gitWriteOperation('Push to origin', gitOptionalBranchBodySchema),+ '/api/git/push-all': gitWriteOperation('Push every branch with unpushed commits', gitPathBodySchema),+ '/api/git/info': gitWriteOperation('Read full git info for a path', gitPathBodySchema),+ '/api/git/branches': gitWriteOperation('List local branches', gitPathBodySchema),+ '/api/git/checkout': gitWriteOperation('Switch to a branch', gitBranchBodySchema),+ '/api/git/pull': gitWriteOperation('Pull from the remote', gitPathBodySchema),+ '/api/git/sync': gitWriteOperation('Pull then push a branch', gitOptionalBranchBodySchema),+ '/api/git/remote-branches': gitWriteOperation('List remote branches with merge status', gitRemoteBranchesBodySchema),+ '/api/git/merge': gitWriteOperation('Merge a branch into the current branch', gitBranchBodySchema),+ '/api/git/checkout-remote': gitWriteOperation('Check out a remote branch locally', gitBranchBodySchema),+ '/api/git/reset-to-default': gitWriteOperation("Discard local changes and match origin's default branch", gitPathBodySchema),+ '/api/git/cleanup-merged': gitWriteOperation('Delete merged branches and their worktrees', gitPathBodySchema),'/api/git/delete-branch': {post: {summary: 'Delete a Git branch locally, remotely, or both',diff --git a/server/lib/gitArgs.js b/server/lib/gitArgs.jsindex a7c3f6c1ce..f8d88135ef 100644--- a/server/lib/gitArgs.js+++ b/server/lib/gitArgs.js@@ -2,6 +2,8 @@// child-process access — these sanitize/shape the inputs that// server/services/git.js passes to execGit.+import { ServerError } from './errorHandler.js';+// Long-lived shared branches that must never be deleted by the branch-cleanup// paths, nor handed to the branch-reconcile coordinator agent — they are not// disposable work. `gh-pages` is the GitHub Pages publishing branch: deleting it@@ -52,11 +54,11 @@ export function validateFilePaths(files) {return fileList.map(f => {// Reject paths with null bytes or command separatorsif (GIT_UNSAFE_CHARS.test(f)) {- throw new Error(`Invalid character in file path: ${f}`);+ throw new ServerError(`Invalid character in file path: ${f}`, { status: 400, code: 'VALIDATION_ERROR' });}// Reject absolute paths or parent directory traversalif (!isGitStageableFilePath(f)) {- throw new Error(`Invalid file path: ${f}`);+ throw new ServerError(`Invalid file path: ${f}`, { status: 400, code: 'VALIDATION_ERROR' });}return f;});@@ -74,3 +76,33 @@ export function validateFilePaths(files) {export function toLiteralPathspec(path) {return `:(literal)${path}`;}++/**+ * True when `ref` is safe to hand to git as a bare branch/ref argument: not+ * option-shaped (leading "-"), and free of whitespace/control characters and the+ * sequences git-check-ref-format forbids (`..`, `@{`, and `~ ^ : ? * [ \`,+ * a trailing "/", ".", or ".lock").+ * @param {unknown} ref+ * @returns {boolean}+ */+export function isSafeGitRef(ref) {+ if (typeof ref !== 'string' || ref.length < 1 || ref.length > 255) return false;+ if (ref.startsWith('-') || ref.startsWith('/')) return false;+ // eslint-disable-next-line no-control-regex+ if (/[\s\x00-\x1f\x7f~^:?*[\\]/.test(ref)) return false;+ if (ref.includes('..') || ref.includes('@{')) return false;+ return !(ref.endsWith('/') || ref.endsWith('.lock') || ref.endsWith('.'));+}++/**+ * Defense in depth for callers that bypass HTTP (CoS services import+ * services/git.js directly): throw a 400 ServerError for an unsafe ref.+ * @param {unknown} ref+ * @returns {string} the ref, unchanged+ */+export function assertSafeRef(ref) {+ if (!isSafeGitRef(ref)) {+ throw new ServerError('Invalid git ref name', { status: 400, code: 'VALIDATION_ERROR' });+ }+ return ref;+}diff --git a/server/lib/validation.js b/server/lib/validation.jsindex 94c3bfcecf..aa041858ce 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -1,16 +1,8 @@import { CREDENTIALS } from './credentialRegistry.js';import { DEFAULT_BACKUP_CRON, MIN_RETENTION_COUNT, MAX_RETENTION_COUNT } 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 { isSafeGitRef } from './gitArgs.js';import { partialWithoutDefaults, emptyToUndefined, emptyToNull, optionalBooleanMap, presetProviderIdSchema, providerRefSchema } from './zodCompat.js';import { WORK_TRACKERS } from './workTracker.js';import { LAYERED_INTELLIGENCE_SOURCE_KEYS } from './layeredIntelligenceSourceKeys.js';@@ -43,6 +35,49 @@ import { isValidCronExpression, isCronShaped } from './cronValidation.js';import { USER_ACTION_ACTORS, USER_ACTION_TYPES } from './userActionTypes.js';import { MIND_BUNDLE_GROUP_CHOICES, MIND_BUNDLE_MAX_CHARS, MIND_BUNDLE_PASSPHRASE_MAX_CHARS, MIND_BUNDLE_PASSPHRASE_MIN_CHARS, PERSISTENT_MIND_BUNDLE_GROUPS, PERSISTENT_MIND_BUNDLE_SCOPES } from './mindBundleFormat.js';+// ---- Git write-route bodies (#9154) -----------------------------------------+// Refs and files become argv entries for git, so a leading "-" would be parsed+// as an option; the ref grammar rejects that plus git's own invalid-ref forms.+export const gitRefNameSchema = z.string().min(1).max(255).refine(isSafeGitRef, {+ message: 'not a valid git ref name',+});+const gitPathField = z.string().min(1);++export const gitPathBodySchema = z.object({ path: gitPathField });+export const gitStageBodySchema = z.object({+ path: gitPathField,+ files: z.array(z.string().min(1)).min(1).max(500),+});+export const gitCommitBodySchema = z.object({+ path: gitPathField,+ message: z.string().min(1).max(10000),+});+export const gitBranchBodySchema = z.object({ path: gitPathField, branch: gitRefNameSchema });+export const gitOptionalBranchBodySchema = z.object({+ path: gitPathField,+ branch: gitRefNameSchema.nullish(),+});+export const gitBranchComparisonBodySchema = z.object({+ path: gitPathField,+ base: gitRefNameSchema.nullish(),+ head: gitRefNameSchema.nullish(),+});+export const gitDiffBodySchema = z.object({ path: gitPathField, staged: z.boolean().default(false) });+export const gitCommitsBodySchema = z.object({+ path: gitPathField,+ limit: z.number().int().min(1).max(100).default(10),+});+export const gitRemoteBranchesBodySchema = z.object({ path: gitPathField, force: z.boolean().default(false) });+export const gitDeleteBranchBodySchema = z.object({+ path: gitPathField,+ branch: gitRefNameSchema,+ 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',+});++// gpt-image-2 (codex backend) caps at 3840px per edge and 8,294,400 total// pixels. Mirror the ceiling for every image-gen route. Local mflux can// render up to 3840 in principle but is impractically slow past ~2048 — thediff --git a/server/routes/git.js b/server/routes/git.jsindex 671ac93645..4bccdb7570 100644--- a/server/routes/git.js+++ b/server/routes/git.js@@ -8,7 +8,9 @@ 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, gitDeleteBranchBodySchema } from '../lib/validation.js';+import { validateRequest, submoduleStatusQuerySchema, submoduleUpdateSchema, gitDeleteBranchBodySchema,+ gitPathBodySchema, gitStageBodySchema, gitCommitBodySchema, gitBranchBodySchema, gitOptionalBranchBodySchema,+ gitBranchComparisonBodySchema, gitDiffBodySchema, gitCommitsBodySchema, gitRemoteBranchesBodySchema } from '../lib/validation.js';/*** Assert that a caller-supplied workspace path exists, is a directory, and@@ -98,7 +100,7 @@ router.get('/:appId', asyncHandler(async (req, res) => {// POST /api/git/status - Get status for a pathrouter.post('/status', asyncHandler(async (req, res) => {- const { path } = req.body;+ const { path } = validateRequest(gitPathBodySchema, req.body);assertAllowedWorkspace(path);const status = await git.getStatus(path);res.json(status);@@ -106,7 +108,7 @@ router.post('/status', asyncHandler(async (req, res) => {// POST /api/git/diff - Get diff for a pathrouter.post('/diff', asyncHandler(async (req, res) => {- const { path, staged } = req.body;+ const { path, staged } = validateRequest(gitDiffBodySchema, req.body);assertAllowedWorkspace(path);const diff = await git.getDiff(path, staged);res.json({ diff });@@ -114,7 +116,7 @@ router.post('/diff', asyncHandler(async (req, res) => {// POST /api/git/commits - Get recent commitsrouter.post('/commits', asyncHandler(async (req, res) => {- const { path, limit = 10 } = req.body;+ const { path, limit } = validateRequest(gitCommitsBodySchema, req.body);assertAllowedWorkspace(path);const commits = await git.getCommits(path, limit);res.json({ commits });@@ -122,40 +124,31 @@ router.post('/commits', asyncHandler(async (req, res) => {// POST /api/git/stage - Stage filesrouter.post('/stage', asyncHandler(async (req, res) => {- const { path, files } = req.body;+ const { path, files } = validateRequest(gitStageBodySchema, req.body);assertAllowedWorkspace(path);- if (!files) {- throw new ServerError('files is required', { status: 400, code: 'VALIDATION_ERROR' });- }await git.stageFiles(path, files);res.json({ success: true });}));// POST /api/git/unstage - Unstage filesrouter.post('/unstage', asyncHandler(async (req, res) => {- const { path, files } = req.body;+ const { path, files } = validateRequest(gitStageBodySchema, req.body);assertAllowedWorkspace(path);- if (!files) {- throw new ServerError('files is required', { status: 400, code: 'VALIDATION_ERROR' });- }await git.unstageFiles(path, files);res.json({ success: true });}));// POST /api/git/commit - Create a commitrouter.post('/commit', asyncHandler(async (req, res) => {- const { path, message } = req.body;+ const { path, message } = validateRequest(gitCommitBodySchema, req.body);assertAllowedWorkspace(path);- if (!message) {- throw new ServerError('message is required', { status: 400, code: 'VALIDATION_ERROR' });- }const result = await git.commit(path, message);res.json(result);}));// POST /api/git/update-branches - Fetch and merge latest dev and mainrouter.post('/update-branches', asyncHandler(async (req, res) => {- const { path } = req.body;+ const { path } = validateRequest(gitPathBodySchema, req.body);assertAllowedWorkspace(path);const result = await git.updateBranches(path);res.json(result);@@ -163,7 +156,7 @@ router.post('/update-branches', asyncHandler(async (req, res) => {// POST /api/git/branch-comparison - Compare two branchesrouter.post('/branch-comparison', asyncHandler(async (req, res) => {- const { path, base, head } = req.body;+ const { path, base, head } = validateRequest(gitBranchComparisonBodySchema, req.body);assertAllowedWorkspace(path);const baseBranch = base || await git.getDefaultBranch(path, { allowRemote: false }).catch(() => null) || 'main';const result = await git.getBranchComparison(path, baseBranch, head || 'dev');@@ -172,7 +165,7 @@ router.post('/branch-comparison', asyncHandler(async (req, res) => {// POST /api/git/push - Push to originrouter.post('/push', asyncHandler(async (req, res) => {- const { path, branch } = req.body;+ const { path, branch } = validateRequest(gitOptionalBranchBodySchema, req.body);assertAllowedWorkspace(path);const result = await git.push(path, branch);res.json(result);@@ -180,7 +173,7 @@ router.post('/push', asyncHandler(async (req, res) => {// POST /api/git/push-all - Push all branches with unpushed commitsrouter.post('/push-all', asyncHandler(async (req, res) => {- const { path } = req.body;+ const { path } = validateRequest(gitPathBodySchema, req.body);assertAllowedWorkspace(path);const result = await git.pushAll(path);res.json(result);@@ -188,7 +181,7 @@ router.post('/push-all', asyncHandler(async (req, res) => {// POST /api/git/info - Get full git info for a pathrouter.post('/info', asyncHandler(async (req, res) => {- const { path } = req.body;+ const { path } = validateRequest(gitPathBodySchema, req.body);assertAllowedWorkspace(path);const info = await git.getGitInfo(path);res.json(info);@@ -196,7 +189,7 @@ router.post('/info', asyncHandler(async (req, res) => {// POST /api/git/branches - Get all local branchesrouter.post('/branches', asyncHandler(async (req, res) => {- const { path } = req.body;+ const { path } = validateRequest(gitPathBodySchema, req.body);assertAllowedWorkspace(path);const branches = await git.getBranches(path);res.json({ branches });@@ -204,18 +197,15 @@ router.post('/branches', asyncHandler(async (req, res) => {// POST /api/git/checkout - Switch to a branchrouter.post('/checkout', asyncHandler(async (req, res) => {- const { path, branch } = req.body;+ const { path, branch } = validateRequest(gitBranchBodySchema, req.body);assertAllowedWorkspace(path);- if (!branch) {- throw new ServerError('branch is required', { status: 400, code: 'VALIDATION_ERROR' });- }const result = await git.checkout(path, branch);res.json(result);}));// POST /api/git/pull - Pull changes from remoterouter.post('/pull', asyncHandler(async (req, res) => {- const { path } = req.body;+ const { path } = validateRequest(gitPathBodySchema, req.body);assertAllowedWorkspace(path);const result = await git.pull(path);res.json(result);@@ -223,7 +213,7 @@ router.post('/pull', asyncHandler(async (req, res) => {// POST /api/git/sync - Sync branch (pull then push)router.post('/sync', asyncHandler(async (req, res) => {- const { path, branch } = req.body;+ const { path, branch } = validateRequest(gitOptionalBranchBodySchema, req.body);assertAllowedWorkspace(path);const result = await git.syncBranch(path, branch);res.json(result);@@ -231,7 +221,7 @@ router.post('/sync', asyncHandler(async (req, res) => {// POST /api/git/remote-branches - Get remote branches with merge statusrouter.post('/remote-branches', asyncHandler(async (req, res) => {- const { path, force } = req.body;+ const { path, force } = validateRequest(gitRemoteBranchesBodySchema, req.body);assertAllowedWorkspace(path);const result = await git.getRemoteBranches(path, { force });res.json(result);@@ -239,22 +229,16 @@ router.post('/remote-branches', asyncHandler(async (req, res) => {// POST /api/git/merge - Merge a branch into the current branchrouter.post('/merge', asyncHandler(async (req, res) => {- const { path, branch } = req.body;+ const { path, branch } = validateRequest(gitBranchBodySchema, req.body);assertAllowedWorkspace(path);- if (!branch) {- throw new ServerError('branch is required', { status: 400, code: 'VALIDATION_ERROR' });- }const result = await git.mergeBranch(path, branch);res.json(result);}));// POST /api/git/checkout-remote - Checkout a remote branch locallyrouter.post('/checkout-remote', asyncHandler(async (req, res) => {- const { path, branch } = req.body;+ const { path, branch } = validateRequest(gitBranchBodySchema, req.body);assertAllowedWorkspace(path);- if (!branch) {- throw new ServerError('branch is required', { status: 400, code: 'VALIDATION_ERROR' });- }const result = await git.checkoutRemoteBranch(path, branch);res.json(result);}));@@ -264,7 +248,7 @@ router.post('/checkout-remote', asyncHandler(async (req, res) => {// the response carries the pre-reset HEAD so the caller can offer a recovery// sha. See git.resetToDefaultBranch for the full contract.router.post('/reset-to-default', asyncHandler(async (req, res) => {- const { path } = req.body;+ const { path } = validateRequest(gitPathBodySchema, req.body);assertAllowedWorkspace(path);const result = await git.resetToDefaultBranch(path);res.json(result);@@ -275,7 +259,7 @@ router.post('/reset-to-default', asyncHandler(async (req, res) => {// it is clean and its branch is fully in origin/<default>; anything else comes// back in `skipped` with the reason.router.post('/cleanup-merged', asyncHandler(async (req, res) => {- const { path } = req.body;+ const { path } = validateRequest(gitPathBodySchema, req.body);assertAllowedWorkspace(path);const { excludeBranches, activeAgentIds } = await getAgentProtections();const result = await git.deleteMergedBranches(path, { excludeBranches, activeAgentIds });diff --git a/server/routes/git.test.js b/server/routes/git.test.jsindex 48d7110282..a890e22492 100644--- a/server/routes/git.test.js+++ b/server/routes/git.test.js@@ -457,3 +457,68 @@ describe('git routes — submodules', () => {expect(gitSubmoduleService.updateSubmodule).not.toHaveBeenCalled();});});++describe('git routes — body validation (#9154)', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ allowWorkspace();+ });++ const P = '/Users/me/project';++ it.each(['checkout', 'merge', 'checkout-remote', 'push', 'sync'])(+ 'POST /%s rejects option-shaped, malformed, and non-string branches with 400 and no git call',+ async (route) => {+ for (const branch of ['-f', '--force', '--abort', '-B x', 'a..b', 'a b', {}, 5]) {+ const res = await request(makeApp()).post(`/api/git/${route}`).send({ path: P, branch });+ expect(res.status).toBe(400);+ expect(res.body.code).toBe('VALIDATION_ERROR');+ }+ expect(gitService[route === 'checkout-remote' ? 'checkoutRemoteBranch' : route === 'merge' ? 'mergeBranch' : route === 'sync' ? 'syncBranch' : route]).not.toHaveBeenCalled();+ }+ );++ it('POST /branch-comparison rejects option-shaped base/head', async () => {+ for (const body of [{ base: '-f' }, { head: '--force' }, { base: 'a..b' }]) {+ const res = await request(makeApp()).post('/api/git/branch-comparison').send({ path: P, ...body });+ expect(res.status).toBe(400);+ }+ expect(gitService.getBranchComparison).not.toHaveBeenCalled();+ });++ it('accepts ordinary branch names', async () => {+ for (const branch of ['main', 'feature/foo-1', 'release/1.2.3']) {+ const res = await request(makeApp()).post('/api/git/checkout').send({ path: P, branch });+ expect(res.status).toBe(200);+ expect(gitService.checkout).toHaveBeenCalledWith(P, branch);+ }+ });++ it.each(['stage', 'unstage'])('POST /%s rejects non-array files with 400', async (route) => {+ for (const files of [5, 'a.js', [], [1], {}]) {+ const res = await request(makeApp()).post(`/api/git/${route}`).send({ path: P, files });+ expect(res.status).toBe(400);+ }+ });++ it('validateFilePaths failures surface as 400, not 500', async () => {+ const { validateFilePaths } = await import('../lib/gitArgs.js');+ gitService.stageFiles.mockImplementation(async (_d, files) => validateFilePaths(files));+ for (const files of [['../x'], ['/etc/passwd']]) {+ const res = await request(makeApp()).post('/api/git/stage').send({ path: P, files });+ expect(res.status).toBe(400);+ expect(res.body.code).toBe('VALIDATION_ERROR');+ }+ });++ it.each([+ ['/diff', { staged: 'true' }],+ ['/diff', { staged: 1 }],+ ['/remote-branches', { force: 'false' }],+ ['/commits', { limit: '5' }],+ ['/commit', { message: ['a'] }],+ ])('POST %s rejects wrongly typed %j', async (route, extra) => {+ const res = await request(makeApp()).post(`/api/git${route}`).send({ path: P, ...extra });+ expect(res.status).toBe(400);+ });+});diff --git a/server/services/git.js b/server/services/git.jsindex 8fdec544c3..de7b968038 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -21,7 +21,7 @@ import {detectForgeCli,parsePullRequestUrl} from '../lib/gitForge.js';-import { PROTECTED_BRANCHES, validateFilePaths, toLiteralPathspec } from '../lib/gitArgs.js';+import { PROTECTED_BRANCHES, validateFilePaths, toLiteralPathspec, assertSafeRef } from '../lib/gitArgs.js';import { ServerError } from '../lib/errorHandler.js';// Re-export so callers that used to import from services/git.js keep working.@@ -294,6 +294,8 @@ export async function updateBranches(dir) {* Get branch comparison (how far ahead headBranch is from baseBranch)*/export async function getBranchComparison(dir, baseBranch = 'main', headBranch = 'dev') {+ assertSafeRef(baseBranch);+ assertSafeRef(headBranch);const format = '--format={"hash":"%h","message":"%s","author":"%an","date":"%cI"}';const logResult = await execGit(['log', format, `${baseBranch}..${headBranch}`], dir, { ignoreExitCode: true }@@ -320,6 +322,7 @@ export async function getBranchComparison(dir, baseBranch = 'main', headBranch =* Push to origin*/export async function push(dir, branch = null) {+ if (branch) assertSafeRef(branch);const args = branch ? ['push', 'origin', branch] : ['push'];const result = await execGit(args, dir);return { success: true, output: result.stdout + result.stderr };@@ -369,6 +372,7 @@ export async function createBranch(dir, branchName) {* Switch to an existing branch*/export async function checkout(dir, branchName) {+ assertSafeRef(branchName);await execGit(['checkout', branchName], dir);return { success: true, branch: branchName };}@@ -946,6 +950,7 @@ export async function updateDefaultBranch(dir) {* Sync branch - pull then push*/export async function syncBranch(dir, branch = null) {+ if (branch) assertSafeRef(branch);const currentBranch = branch || await getBranch(dir);// First pull with rebase@@ -1327,6 +1332,7 @@ export async function deleteBranch(dir, branchName, { local = false, remote = fa* @returns {Promise<{success: boolean, output: string}>}*/export async function mergeBranch(dir, branchName) {+ assertSafeRef(branchName);const result = await execGit(['merge', '--no-ff', branchName], dir);return { success: true, output: (result.stdout + result.stderr).trim() };}@@ -1423,6 +1429,7 @@ export const isBranchMergedInto = hasBranchMergeEvidence;* @returns {Promise<{success: boolean, branch: string}>}*/export async function checkoutRemoteBranch(dir, branchName) {+ assertSafeRef(branchName);await execGit(['checkout', '-b', branchName, `origin/${branchName}`], dir);return { success: true, branch: branchName };}