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(server): cap conversation message page size

Coff0xcbf6feefbdfd6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9ee6faa..e4076e0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -50,6 +50,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.
+- **Conversation message pages**: `GET /api/conversations/{id}/messages` clamps `limit` (200 for history, 1000 for `?since=`), so a huge query cannot load the whole transcript in one response.
- **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/server/conversations.go b/server/conversations.go
index 7c0d916..cb810ae 100644
--- a/server/conversations.go
+++ b/server/conversations.go
@@ -311,16 +311,16 @@ func (s *Server) pgConversationMessages(w http.ResponseWriter, r *http.Request)
return
}
q := r.URL.Query()
- limit := atoiDefault(q.Get("limit"), 200)
s.chatMu.Lock()
running := s.chatBusy[s.convBusyKey(c.ID)]
s.chatMu.Unlock()
// Incremental tail: ?since=N returns steps after id N (ASC) — used by the live
- // poll and the post-send fetch. A generous cap so a burst is never dropped.
+ // poll and the post-send fetch. Capped so a huge limit cannot materialise the
+ // whole transcript in one response.
if sv := q.Get("since"); sv != "" {
since, _ := strconv.ParseInt(sv, 10, 64)
- items, cursor, err := pg.ConvActivityList(c.ID, since, max(limit, 1000))
+ items, cursor, err := pg.ConvActivityList(c.ID, since, 1000)
if err != nil {
writeErr(w, 500, err.Error())
return
@@ -333,7 +333,7 @@ func (s *Server) pgConversationMessages(w http.ResponseWriter, r *http.Request)
// the page of older steps ending before id N. hasMore lets the client stop
// loading earlier history once the top of the thread is reached.
before, _ := strconv.ParseInt(q.Get("before"), 10, 64)
- items, hasMore, err := pg.ConvActivityPage(c.ID, before, limit)
+ items, hasMore, err := pg.ConvActivityPage(c.ID, before, convMessageLimit(q.Get("limit"), 200, 200))
if err != nil {
writeErr(w, 500, err.Error())
return
@@ -345,6 +345,19 @@ func (s *Server) pgConversationMessages(w http.ResponseWriter, r *http.Request)
writeJSON(w, 200, map[string]any{"items": activityDTOs(items), "cursor": cursor, "running": running, "hasMore": hasMore})
}
+// convMessageLimit clamps a page size. Missing or invalid values use def; the
+// result is at most cap so a huge query cannot materialise the whole transcript.
+func convMessageLimit(raw string, maxN, def int) int {
+ n := atoiDefault(raw, def)
+ if n < 1 {
+ n = def
+ }
+ if n > maxN {
+ n = maxN
+ }
+ return n
+}
+
// pgConversationMsgDetail lazily returns one step's full detail blob.
func (s *Server) pgConversationMsgDetail(w http.ResponseWriter, r *http.Request) {
pg, c, ok := s.convByID(w, r)
diff --git a/server/conversations_limit_test.go b/server/conversations_limit_test.go
new file mode 100644
index 0000000..7813a7d
--- /dev/null
+++ b/server/conversations_limit_test.go
@@ -0,0 +1,21 @@
+package server
+
+import "testing"
+
+func TestConvMessageLimit(t *testing.T) {
+ if got := convMessageLimit("", 200, 200); got != 200 {
+ t.Fatalf("default: %d", got)
+ }
+ if got := convMessageLimit("50", 200, 200); got != 50 {
+ t.Fatalf("50: %d", got)
+ }
+ if got := convMessageLimit("2147483646", 200, 200); got != 200 {
+ t.Fatalf("huge history: %d", got)
+ }
+ if got := convMessageLimit("2147483646", 1000, 1000); got != 1000 {
+ t.Fatalf("huge since: %d", got)
+ }
+ if got := convMessageLimit("-1", 200, 200); got != 200 {
+ t.Fatalf("negative: %d", got)
+ }
+}