fix(egress): reject overflowing Retry-After values

strconv.Atoi accepted a huge Retry-After, then time.Duration(n)*Second
wrapped so the delay looked smaller than MaxDelay and the governor
retried immediately. Parse as int64 and refuse anything above MaxDelay.
This commit is contained in:
Coff0xc
2026-11-19 14:23:32 +01:00
committed by BaaRai
parent 05d320878b
commit 7bbb0267e4
3 changed files with 14 additions and 2 deletions
+1
View File
@@ -49,6 +49,7 @@ All notable changes to this project are documented in this file. The format is b
### Fixed
- **Retry-After overflow**: a 429/503 `Retry-After` of huge seconds no longer wraps `time.Duration` into a tiny delay. Values above `MaxDelay` are not retried.
- **Findings CSV formula cells**: `FindingsCSV` prefixes name, class, summary, task, and other text fields that start with `=`, `+`, `-`, `@`, tab, or CR so Excel/LibreOffice do not evaluate them as formulas when the export is opened.
- **Asset service links**: the Services tab only uses an asset URL as `href` when it is `http:` or `https:`. `javascript:`, `data:`, and other schemes render as text.
- **Chat session directories**: `ChatAgent.Chat` accepts only `[A-Za-z0-9_-]` session ids (at most 64 bytes) before joining them under `<workDir>/sessions`, so `..` and path separators cannot escape that directory.
+9 -2
View File
@@ -250,8 +250,15 @@ func (g *Governor) reserve(h *hostState) time.Duration {
// asks for more than MaxDelay.
func (g *Governor) backoff(h http.Header, attempt int) (d time.Duration, ok bool) {
v := strings.TrimSpace(h.Get("Retry-After"))
if n, err := strconv.Atoi(v); err == nil && n >= 0 {
return time.Duration(n) * time.Second, time.Duration(n)*time.Second <= g.p.MaxDelay
if n, err := strconv.ParseInt(v, 10, 64); err == nil && n >= 0 {
maxSec := int64(g.p.MaxDelay / time.Second)
if maxSec < 0 {
maxSec = 0
}
if n > maxSec {
return 0, false
}
return time.Duration(n) * time.Second, true
}
if t, err := http.ParseTime(v); err == nil {
return max(time.Until(t), 0), time.Until(t) <= g.p.MaxDelay
+4
View File
@@ -145,6 +145,10 @@ func TestBackoff(t *testing.T) {
if d, ok := g.backoff(h, 0); !ok || d <= 0 || d > 2*time.Second {
t.Fatalf("HTTP-date Retry-After: %s, %v", d, ok)
}
// A huge second count used to wrap Duration and look like an immediate retry.
if d, ok := g.backoff(http.Header{"Retry-After": {"9223372036854775807"}}, 0); ok || d != 0 {
t.Fatalf("overflow Retry-After: %s %v, want refuse", d, ok)
}
}
func TestDedupeAndCache(t *testing.T) {