fix: agent security and linting improvements - #3831
Conversation
- Fix goroutine leak in RAG file watcher - Prevent NUL byte truncation injection in script shell env vars - Fix errorlint, noctx, and bodyclose linter warnings on Windows - Restore and manage necessary gosec directives
|
Same here @Piyush0049 Please provide more details about the issue you are trying to solve. Is it something which happens often? What are the symptoms? Right now the PR doesn't provide enough context to understand if you are fixing a bug or if these are just code reviews by an LLM which could easily hallucinate bugs. Thanks |
|
@aheritier here is a detailed file-by-file breakdown of the 6 files modified in this PR: 1. Bug Fixes & Security (2 Files)
2. Windows Cross-Platform Linter Cleanups (4 Files)
Summary (Before vs After)
|
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🔴 CRITICAL
One high-severity confirmed bug was found in the new goroutine-lifecycle code added by this PR.
|
Thanks for the PR! One thing needs fixing before this can go in: In watchCtx, cancel := context.WithCancel(ctx)
t.cancelWatcher = cancel // set unconditionally
if err := t.manager.Initialize(ctx); err != nil {
cancel()
return ... // watcherDone is still nil
}
t.watcherDone = make(chan struct{})
// Stop():
if t.cancelWatcher != nil {
t.cancelWatcher()
<-t.watcherDone // nil channel -> blocks forever
}This matters because Reproduced locally on this branch with a mock strategy whose Note that commit ec033bb is what introduced it: it moved Minimal fix: if t.watcherDone != nil {
<-t.watcherDone
}Cleaner: create the channel up front and |
|
@dgageot I have pushed a commit addressing the changes you asked to do. Please do let me know if any other changes are required. |
Description
This PR introduces critical fixes for agent stability and defense in depth security, alongside resolving native Windows linting warnings.
Key Changes
forwardEventsandStartFileWatchergoroutines are cleanly terminated whenStop()is called, preventing silent memory and file descriptor leaks across tool reloads.\x00validation to static environment variables inscript_shell.go. This prevents malicious or malformedconfig.yamlfiles from injecting NUL bytes that would silently truncate the process environment at the kernelexecveboundary.errorlint,noctx, andbodyclosewarnings in Windows specific files (usingerrors.As,context.Background(), and explicit body closure) and safely managedgosecdirectives to ensure a perfectly cleangolangci-lint runstate.Testing Instructions
golangci-lint runreports 0 issues.task testpasses successfully.