Harden remote API security boundaries
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user