Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

fix(egress): reject overflowing Retry-After values

Coff0xc7bbb0267e469
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 74f6a55..9ee6faa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/egress/egress.go b/egress/egress.go
index e64e474..a21390c 100644
--- a/egress/egress.go
+++ b/egress/egress.go
@@ -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
diff --git a/egress/egress_test.go b/egress/egress_test.go
index 11a16ec..55424e5 100644
--- a/egress/egress_test.go
+++ b/egress/egress_test.go
@@ -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) {