From 03289716b48e8f743a2003a4debe67e418532508 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Thu, 28 May 2026 17:17:36 +0800 Subject: [PATCH] fix: fix ClamAV scan failure issue --- agent/utils/clam/clam.go | 9 +++++++-- agent/utils/cmd/cmdx.go | 17 ++++++++++++++++- core/app/api/v2/auth.go | 8 ++++++-- core/middleware/operation.go | 11 +++++++++-- core/utils/cmd/cmdx.go | 17 ++++++++++++++++- .../src/views/cronjob/cronjob/record/index.vue | 2 +- .../src/views/toolbox/clam/record/index.vue | 2 +- 7 files changed, 56 insertions(+), 10 deletions(-) diff --git a/agent/utils/clam/clam.go b/agent/utils/clam/clam.go index 29a867170cb9..a9ce6cc93c26 100644 --- a/agent/utils/clam/clam.go +++ b/agent/utils/clam/clam.go @@ -32,9 +32,14 @@ func AddScanTask(taskItem *task.Task, clam model.Clam, timeNow string) { } strategy = fmt.Sprintf("--%s=%s", clam.InfectedStrategy, dir) } - taskItem.Logf("clamdscan --fdpass %s %s", strategy, clam.Path) + args := []string{"--fdpass"} + if strategy != "" { + args = append(args, strategy) + } + args = append(args, clam.Path) + taskItem.Logf("clamdscan %s", strings.Join(args, " ")) mgr := cmd.NewCommandMgr(cmd.WithIgnoreExist1(), cmd.WithTimeout(time.Duration(clam.Timeout)*time.Second), cmd.WithTask(*taskItem)) - if err := mgr.Run("clamdscan", "--fdpass", strategy, clam.Path); err != nil { + if err := mgr.Run("clamdscan", args...); err != nil { return fmt.Errorf("clamdscan failed, %v", err) } return nil diff --git a/agent/utils/cmd/cmdx.go b/agent/utils/cmd/cmdx.go index 376f6b054dc2..b87c886ab637 100644 --- a/agent/utils/cmd/cmdx.go +++ b/agent/utils/cmd/cmdx.go @@ -240,7 +240,7 @@ func (c *CommandHelper) pipeContext() (context.Context, context.CancelFunc) { func (c *CommandHelper) buildPipeCommands(ctx context.Context, commands []PipeCommand) []*exec.Cmd { cmds := make([]*exec.Cmd, 0, len(commands)) for _, item := range commands { - cmdItem := exec.CommandContext(ctx, item.Name, item.Args...) + cmdItem := exec.CommandContext(ctx, item.Name, filterEmptyArgs(item.Args)...) cmdItem.Env = append(os.Environ(), c.env...) cmdItem.Env = append(cmdItem.Env, item.Env...) cmdItem.Dir = c.workDir @@ -305,6 +305,7 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) { var newContext context.Context var cancel context.CancelFunc var outputFile *os.File + arg = filterEmptyArgs(arg) if c.timeout != 0 { if c.context == nil { @@ -411,6 +412,20 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) { } } +func filterEmptyArgs(args []string) []string { + if len(args) == 0 { + return args + } + filtered := args[:0] + for _, arg := range args { + if arg == "" { + continue + } + filtered = append(filtered, arg) + } + return filtered +} + func contextDone(ctx context.Context) <-chan struct{} { if ctx == nil { return nil diff --git a/core/app/api/v2/auth.go b/core/app/api/v2/auth.go index 2839e40a2885..55575137e78c 100644 --- a/core/app/api/v2/auth.go +++ b/core/app/api/v2/auth.go @@ -63,7 +63,7 @@ func (b *BaseApi) Login(c *gin.Context) { if user == nil || user.MfaStatus != constant.StatusEnable { go saveLoginLogs(c, req.Name, wrapLoginErr(msgKey, err)) } - if msgKey == "ErrAuth" || msgKey == "ErrEntrance" { + if msgKey == "ErrAuth" || msgKey == "ErrEntrance" || msgKey == "ErrNoneNode" { if msgKey == "ErrAuth" { global.IPTracker.RecordFailure(ip) global.IPTracker.SetNeedCaptcha(ip) @@ -109,6 +109,10 @@ func (b *BaseApi) MFALogin(c *gin.Context) { user, msgKey, err := xpack.AuthProvider.MFALogin(c, req, string(entrance)) go saveLoginLogs(c, loginLogUserName(user, req.SessionID), wrapLoginErr(msgKey, err)) + if msgKey == "ErrNoneNode" { + helper.BadAuth(c, msgKey, err) + return + } if msgKey == "ErrMFA" { global.IPTracker.RecordFailure(ip) failures := initauth.GetMFASessionStore().RecordFailure(req.SessionID) @@ -164,7 +168,7 @@ func (b *BaseApi) PasskeyFinishLogin(c *gin.Context) { entrance := loadEntranceFromRequest(c) user, msgKey, err := xpack.AuthProvider.PasskeyFinishLogin(c, sessionID, entrance) go saveLoginLogs(c, loginLogUserName(user, ""), wrapLoginErr(msgKey, err)) - if msgKey == "ErrAuth" || msgKey == "ErrEntrance" { + if msgKey == "ErrAuth" || msgKey == "ErrEntrance" || msgKey == "ErrNoneNode" { if msgKey == "ErrAuth" { global.IPTracker.SetNeedCaptcha(common.GetRealClientIP(c)) } diff --git a/core/middleware/operation.go b/core/middleware/operation.go index 7fcae5dc426c..1b28c0aaba0f 100644 --- a/core/middleware/operation.go +++ b/core/middleware/operation.go @@ -183,14 +183,21 @@ func OperationLog() gin.HandlerFunc { func loadOperationUser(c *gin.Context) string { sessionUser, ok := c.Get(psessionUtils.GinContextSessionUserKey) + if ok { + psession, ok := sessionUser.(psessionUtils.SessionUser) + if ok { + return psession.Name + } + } + apiUsername, ok := c.Get("API_AUTH_USERNAME") if !ok { return "" } - psession, ok := sessionUser.(psessionUtils.SessionUser) + username, ok := apiUsername.(string) if !ok { return "" } - return psession.Name + return username } func fillOperationDetail(operationDic *operationJson, formatMap map[string]interface{}) { diff --git a/core/utils/cmd/cmdx.go b/core/utils/cmd/cmdx.go index dceafd870be9..d29ecca1ebe8 100644 --- a/core/utils/cmd/cmdx.go +++ b/core/utils/cmd/cmdx.go @@ -219,7 +219,7 @@ func (c *CommandHelper) pipeContext() (context.Context, context.CancelFunc) { func (c *CommandHelper) buildPipeCommands(ctx context.Context, commands []PipeCommand) []*exec.Cmd { cmds := make([]*exec.Cmd, 0, len(commands)) for _, item := range commands { - cmdItem := exec.CommandContext(ctx, item.Name, item.Args...) + cmdItem := exec.CommandContext(ctx, item.Name, filterEmptyArgs(item.Args)...) cmdItem.Env = append(os.Environ(), c.env...) cmdItem.Env = append(cmdItem.Env, item.Env...) cmdItem.Dir = c.workDir @@ -284,6 +284,7 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) { var newContext context.Context var cancel context.CancelFunc var outputFile *os.File + arg = filterEmptyArgs(arg) if c.timeout != 0 { if c.context == nil { @@ -378,6 +379,20 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) { } } +func filterEmptyArgs(args []string) []string { + if len(args) == 0 { + return args + } + filtered := args[:0] + for _, arg := range args { + if arg == "" { + continue + } + filtered = append(filtered, arg) + } + return filtered +} + func contextDone(ctx context.Context) <-chan struct{} { if ctx == nil { return nil diff --git a/frontend/src/views/cronjob/cronjob/record/index.vue b/frontend/src/views/cronjob/cronjob/record/index.vue index 9733dec86676..c5e6d8bab882 100644 --- a/frontend/src/views/cronjob/cronjob/record/index.vue +++ b/frontend/src/views/cronjob/cronjob/record/index.vue @@ -104,7 +104,7 @@