Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
fix(flows): keep serving readable paths when one container path fails
Sergey Kozyrenko93d36c9827ed
diff --git a/backend/pkg/server/services/flow_files.go b/backend/pkg/server/services/flow_files.goindex 9422633f..26155ae0 100644--- a/backend/pkg/server/services/flow_files.go+++ b/backend/pkg/server/services/flow_files.go@@ -967,18 +967,42 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {seenFailPaths := make(map[string]struct{})allFiles := make([]models.ContainerFile, 0)allFailures := make([]models.ContainerFileError, 0)++ // A directory-level failure on ONE path (nonexistent, not a directory, list+ // command failed) records that path as a failure and keeps serving the paths+ // that worked — only a cancelled request (client gone) aborts the response. If+ // EVERY path fails at the directory level, nothing could be listed and the+ // request is failed as a whole (checked after the loop).+ pathsListed := 0+ var firstPathErr error+ recordPathFailure := func(p string, err error) {+ if firstPathErr == nil {+ firstPathErr = err+ }+ if _, seen := seenFailPaths[p]; seen {+ return+ }+ seenFailPaths[p] = struct{}{}+ allFailures = append(allFailures, models.ContainerFileError{+ Name: path.Base(p),+ Path: p,+ Message: err.Error(),+ })+ }+for _, containerPath := range containerPaths {pathStat, err := s.dockerClient.ContainerStatPath(c.Request.Context(), containerName, containerPath)if err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "container_path": containerPath,- }).Error("error stating container path")- response.Error(c, response.ErrInternal, err)- return+ if cerr := c.Request.Context().Err(); cerr != nil {+ response.Error(c, response.ErrInternal, cerr)+ return+ }+ recordPathFailure(containerPath, err)+ continue}if !pathStat.Mode.IsDir() {+ pathsListed++file := convertContainerFile(path.Dir(containerPath), pathStat)if _, seen := seenPaths[file.Path]; !seen {seenPaths[file.Path] = struct{}{}@@ -989,13 +1013,14 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {listing, err := s.dockerClient.ListContainerDir(c.Request.Context(), containerName, containerPath)if err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "container_path": containerPath,- }).Error("error listing container directory")- response.Error(c, response.ErrInternal, err)- return+ if cerr := c.Request.Context().Err(); cerr != nil {+ response.Error(c, response.ErrInternal, cerr)+ return+ }+ recordPathFailure(containerPath, err)+ continue}+ pathsListed++for _, stat := range listing.Files {file := convertContainerFile(containerPath, stat)if _, seen := seenPaths[file.Path]; !seen {@@ -1004,6 +1029,11 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {}}for _, fe := range listing.Failures {+ // If an overlapping path already read this entry successfully, keep the+ // success and drop the contradictory failure.+ if _, ok := seenPaths[fe.Path]; ok {+ continue+ }if _, seen := seenFailPaths[fe.Path]; seen {continue}@@ -1016,6 +1046,14 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {}}+ // Every requested path failed at the directory level — nothing could be+ // listed, so fail the request instead of returning an empty 200.+ if pathsListed == 0 && len(containerPaths) > 0 {+ logger.FromContext(c).WithError(firstPathErr).WithField("flow_id", flowID).Error("error listing container directory")+ response.Error(c, response.ErrInternal, firstPathErr)+ return+ }+// Sort by name for deterministic output across all paths.sort.Slice(allFiles, func(i, j int) bool {if allFiles[i].Path < allFiles[j].Path {diff --git a/backend/pkg/server/services/flow_files_test.go b/backend/pkg/server/services/flow_files_test.goindex bd43e0ee..307fa42b 100644--- a/backend/pkg/server/services/flow_files_test.go+++ b/backend/pkg/server/services/flow_files_test.go@@ -3325,9 +3325,10 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {wantTotal: 1,},{- // First path succeeds; second path's stat call fails.- // The handler must return 500 (fail-fast).- name: "second path stat error in batch returns internal error",+ // First path succeeds; second path's stat call fails. The readable path+ // is still served (HTTP 200) and the bad path is surfaced as a failure —+ // one bad path no longer blanks the whole multi-path request.+ name: "second path stat error in batch: good path served, bad path a failure",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view", "containers.view"},rawQuery: "paths[]=/work&paths[]=/etc",@@ -3343,12 +3344,15 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {"/work": {{Name: "uploads", Mode: os.ModeDir | 0755}},}},- wantStatus: http.StatusInternalServerError,+ wantStatus: http.StatusOK,+ wantFileNames: []string{"uploads"},+ wantFailureNames: []string{"etc"},},{- // First path directory listing succeeds; second path's listing fails.- // The handler must return 500 (fail-fast).- name: "second path list dir error in batch returns internal error",+ // First path directory listing succeeds; second path's listing fails at+ // the directory level. The readable path is still served (HTTP 200) and+ // the failed path is surfaced as a failure, not a 500.+ name: "second path list dir error in batch: good path served, bad path a failure",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view", "containers.view"},rawQuery: "paths[]=/work&paths[]=/etc",@@ -3365,7 +3369,9 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {"/etc": fmt.Errorf("permission denied"),}},- wantStatus: http.StatusInternalServerError,+ wantStatus: http.StatusOK,+ wantFileNames: []string{"uploads"},+ wantFailureNames: []string{"etc"},},}