diff --git a/internal/server/handler_skills.go b/internal/server/handler_skills.go index 06180e21a..696365873 100644 --- a/internal/server/handler_skills.go +++ b/internal/server/handler_skills.go @@ -217,11 +217,13 @@ func (s *Server) handleUninstallRepo(w http.ResponseWriter, r *http.Request) { defer s.mu.Unlock() name := strings.TrimSpace(r.PathValue("name")) - if name == "" { - writeError(w, http.StatusBadRequest, "tracked repository name is required") + cleanName := filepath.Clean(filepath.FromSlash(name)) + if name == "" || cleanName == "." || cleanName == ".." || filepath.IsAbs(cleanName) || strings.HasPrefix(cleanName, ".."+string(filepath.Separator)) { + writeError(w, http.StatusBadRequest, "invalid or missing tracked repository name") return } + sourceRoot := filepath.Clean(s.cfg.Source) resolveRepo := func(input string) (string, string) { candidates := []string{input} if !strings.HasPrefix(filepath.Base(input), "_") { @@ -232,7 +234,11 @@ func (s *Server) handleUninstallRepo(w http.ResponseWriter, r *http.Request) { } } for _, candidate := range candidates { - repoPath := filepath.Join(s.cfg.Source, candidate) + repoPath := filepath.Clean(filepath.Join(sourceRoot, candidate)) + relPath, relErr := filepath.Rel(sourceRoot, repoPath) + if relErr != nil || relPath == ".." || strings.HasPrefix(relPath, ".."+string(filepath.Separator)) { + continue + } if install.IsGitRepo(repoPath) { return candidate, repoPath } @@ -240,27 +246,31 @@ func (s *Server) handleUninstallRepo(w http.ResponseWriter, r *http.Request) { return "", "" } - repoName, repoPath := resolveRepo(name) + repoName, repoPath := resolveRepo(cleanName) if repoPath == "" { // Fallback: match nested tracked repos by basename. matches := make([]string, 0, 2) - repos, _ := install.GetTrackedRepos(s.cfg.Source) + repos, err := install.GetTrackedRepos(s.cfg.Source) + if err != nil { + writeError(w, http.StatusInternalServerError, "failed to list tracked repositories: "+err.Error()) + return + } for _, repo := range repos { base := filepath.Base(repo) trimmed := strings.TrimPrefix(base, "_") - if base == name || trimmed == name { + if base == cleanName || trimmed == cleanName { matches = append(matches, repo) } } switch len(matches) { case 0: - writeError(w, http.StatusBadRequest, "not a tracked repository: "+name) + writeError(w, http.StatusBadRequest, "not a tracked repository: "+cleanName) return case 1: repoName = matches[0] repoPath = filepath.Join(s.cfg.Source, repoName) default: - writeError(w, http.StatusBadRequest, "multiple tracked repositories match: "+name+" — use the full path") + writeError(w, http.StatusBadRequest, "multiple tracked repositories match: "+cleanName+" — use the full path") return } } diff --git a/ui/src/pages/DashboardPage.tsx b/ui/src/pages/DashboardPage.tsx index defeab0ed..fa3d69c34 100644 --- a/ui/src/pages/DashboardPage.tsx +++ b/ui/src/pages/DashboardPage.tsx @@ -417,9 +417,9 @@ export default function DashboardPage() { function TrackedReposSection({ repos }: { repos: { name: string; skillCount: number; dirty: boolean }[] }) { const queryClient = useQueryClient(); const { toast } = useToast(); - const [updatingRepo, setUpdatingRepo] = useState(null); + const [updatingRepos, setUpdatingRepos] = useState>(new Set()); const [repoToDelete, setRepoToDelete] = useState(null); - const [deletingRepo, setDeletingRepo] = useState(null); + const [deletingRepos, setDeletingRepos] = useState>(new Set()); const invalidateRepoData = async () => { await queryClient.invalidateQueries({ queryKey: queryKeys.overview }); @@ -428,7 +428,7 @@ function TrackedReposSection({ repos }: { repos: { name: string; skillCount: num }; const handleUpdateRepo = async (repoName: string) => { - setUpdatingRepo(repoName); + setUpdatingRepos((prev) => new Set(prev).add(repoName)); try { const res = await api.update({ name: repoName }); const item = res.results[0]; @@ -450,24 +450,33 @@ function TrackedReposSection({ repos }: { repos: { name: string; skillCount: num } catch (e: unknown) { toast((e as Error).message, 'error'); } finally { - setUpdatingRepo(null); + setUpdatingRepos((prev) => { + const next = new Set(prev); + next.delete(repoName); + return next; + }); } }; const handleDeleteRepo = async () => { if (!repoToDelete) return; - setDeletingRepo(repoToDelete); + const targetRepo = repoToDelete; + setDeletingRepos((prev) => new Set(prev).add(targetRepo)); try { - const displayName = repoToDelete.replace(/^_/, ''); - await api.deleteRepo(repoToDelete); + const displayName = targetRepo.replace(/^_/, ''); + await api.deleteRepo(targetRepo); toast(`Repository "${displayName}" uninstalled.`, 'success'); setRepoToDelete(null); await invalidateRepoData(); } catch (e: unknown) { toast((e as Error).message, 'error'); } finally { - setDeletingRepo(null); + setDeletingRepos((prev) => { + const next = new Set(prev); + next.delete(targetRepo); + return next; + }); } }; @@ -485,8 +494,9 @@ function TrackedReposSection({ repos }: { repos: { name: string; skillCount: num
{repos.map((repo) => { const displayName = repo.name.replace(/^_/, ''); - const isUpdating = updatingRepo === repo.name; - const isDeleting = deletingRepo === repo.name; + const isUpdating = updatingRepos.has(repo.name); + const isDeleting = deletingRepos.has(repo.name); + const hasAnyDeleteInProgress = deletingRepos.size > 0; const isBusy = isUpdating || isDeleting; return ( @@ -521,7 +531,7 @@ function TrackedReposSection({ repos }: { repos: { name: string; skillCount: num size="sm" onClick={() => handleUpdateRepo(repo.name)} loading={isUpdating} - disabled={!!deletingRepo} + disabled={hasAnyDeleteInProgress} > Update @@ -530,7 +540,7 @@ function TrackedReposSection({ repos }: { repos: { name: string; skillCount: num variant="danger" size="sm" onClick={() => setRepoToDelete(repo.name)} - disabled={isBusy || !!updatingRepo} + disabled={isBusy || repoToDelete !== null || updatingRepos.size > 0} > Uninstall @@ -552,10 +562,10 @@ function TrackedReposSection({ repos }: { repos: { name: string; skillCount: num } confirmText="Uninstall" variant="danger" - loading={deletingRepo !== null} + loading={repoToDelete !== null && deletingRepos.has(repoToDelete)} onConfirm={handleDeleteRepo} onCancel={() => { - if (!deletingRepo) setRepoToDelete(null); + if (repoToDelete === null || !deletingRepos.has(repoToDelete)) setRepoToDelete(null); }} />