Harden remote API security boundaries

This commit is contained in:
Bohdan Triapitsyn
2026-06-12 18:24:07 +03:00
parent c281937406
commit 106b31a407
52 changed files with 1582 additions and 579 deletions
+88
View File
@@ -222,6 +222,94 @@ export function registerGitRoutes(app) {
}
});
app.get('/api/git/primary-root', async (req, res) => {
const { resolvePrimaryWorktreeRoot } = await getGitLibraries();
try {
const directory = req.query.directory;
if (!directory) {
return res.status(400).json({ error: 'directory parameter is required' });
}
const result = await resolvePrimaryWorktreeRoot(directory);
res.json(result);
} catch (error) {
console.error('Failed to resolve git primary root:', error);
res.status(500).json({ error: error.message || 'Failed to resolve git primary root' });
}
});
app.get('/api/git/toplevel', async (req, res) => {
const { resolveWorktreeTopLevel } = await getGitLibraries();
try {
const directory = req.query.directory;
if (!directory) {
return res.status(400).json({ error: 'directory parameter is required' });
}
const result = await resolveWorktreeTopLevel(directory);
res.json(result);
} catch (error) {
console.error('Failed to resolve git worktree toplevel:', error);
res.status(500).json({ error: error.message || 'Failed to resolve git worktree toplevel' });
}
});
app.post('/api/git/commit-summaries', async (req, res) => {
const { getCommitSummaries } = await getGitLibraries();
try {
const directory = req.query.directory;
if (!directory) {
return res.status(400).json({ error: 'directory parameter is required' });
}
const result = await getCommitSummaries(directory, req.body?.shas);
res.json(result);
} catch (error) {
console.error('Failed to get git commit summaries:', error);
res.status(400).json({ error: error.message || 'Failed to get git commit summaries' });
}
});
const handleIntegrateAction = (action, loadHandler) => {
app.post(`/api/git/integrate/${action}`, async (req, res) => {
try {
const handler = await loadHandler();
const result = await handler(req.body || {});
res.json(result);
} catch (error) {
console.error(`Failed to run git integrate ${action}:`, error);
res.status(400).json({ error: error.message || `Failed to run git integrate ${action}` });
}
});
};
handleIntegrateAction('plan', async () => {
const { computeIntegratePlan } = await getGitLibraries();
return (body) => computeIntegratePlan(body);
});
handleIntegrateAction('conflict-details', async () => {
const { getIntegrateConflictDetails } = await getGitLibraries();
return (body) => getIntegrateConflictDetails(body?.tempWorktreePath);
});
handleIntegrateAction('cherry-pick-status', async () => {
const { isCherryPickInProgress } = await getGitLibraries();
return (body) => isCherryPickInProgress(body?.tempWorktreePath);
});
handleIntegrateAction('run', async () => {
const { integrateWorktreeCommits } = await getGitLibraries();
return (body) => integrateWorktreeCommits(body?.plan);
});
handleIntegrateAction('abort', async () => {
const { abortIntegrate } = await getGitLibraries();
return (body) => abortIntegrate(body?.state);
});
handleIntegrateAction('continue', async () => {
const { continueIntegrate } = await getGitLibraries();
return (body) => continueIntegrate(body?.state);
});
app.get('/api/git/diff', async (req, res) => {
const { getDiff } = await getGitLibraries();
try {