Skip to content

Commit 519ea35

Browse files
fix(model): add 1-minute timeout and body size limit to bash-preexec download
Use http.Client with 1-minute timeout instead of http.Get to prevent hanging on slow/broken networks. Also add io.LimitReader (1MB) to prevent excessive memory usage from unexpected large responses. Co-authored-by: Le He <AnnatarHe@users.noreply.github.com>
1 parent 02368fb commit 519ea35

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

model/shell.bash.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"strings"
10+
"time"
1011

1112
"github.com/gookit/color"
1213
)
@@ -20,7 +21,8 @@ func ensureBashPreexec(hooksDir string) error {
2021
return nil // already exists
2122
}
2223

23-
resp, err := http.Get(bashPreexecURL)
24+
client := &http.Client{Timeout: 1 * time.Minute}
25+
resp, err := client.Get(bashPreexecURL)
2426
if err != nil {
2527
return fmt.Errorf("failed to download bash-preexec.sh: %w", err)
2628
}
@@ -30,7 +32,7 @@ func ensureBashPreexec(hooksDir string) error {
3032
return fmt.Errorf("failed to download bash-preexec.sh: HTTP %d", resp.StatusCode)
3133
}
3234

33-
body, err := io.ReadAll(resp.Body)
35+
body, err := io.ReadAll(io.LimitReader(resp.Body, 1024*1024))
3436
if err != nil {
3537
return fmt.Errorf("failed to read bash-preexec.sh response: %w", err)
3638
}

0 commit comments

Comments
 (0)