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(db): escape backslashes in PostgreSQL text[] literals

Coff0xc7681bacb50f3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6488c72..3558aec 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
+- **PostgreSQL text[] literals escape backslashes**: `marshalStringArray` quoted double quotes but not backslashes, so a value ending in `\"` could close the current array element and inject another. It now doubles backslashes before quotes, matching `marshalJSONBArray`.
- **Browser MCP env null no longer crashes startup**: a stored MCP `env` of JSON `null` unmarshaled into a nil map, and `syncBrowserMCPProxy` then assigned `NODE_EXTRA_CA_CERTS` when traffic capture was on, panicking the process on every start. `decodeStrMap` now always returns a writable map.
- **Provider refusals reported as refusals**: a turn the provider's safety system declined (Anthropic `stop_reason: "refusal"`, OpenAI-compatible `finish_reason: "content_filter"`) has no text and no tool calls, so it ended as `completed` with "the model ended this turn normally", and the idle-turn rerun resent the same conversation up to the empty-response retry count, where it is expected to be refused again. The LLM recorder now hands each call's stop reason to the run (`llmrec.WithStopSink`, `agent.WithStopTracker`). After a refusal the idle-turn rerun is skipped, and the run summary says the provider refused the turn and the intent was not completed.
- **LLM health badge on every task path**: `/system/llm/` read a breaker state that only the failover Pool wrote, so a profile used by an explicit task chain, by a bound agent with failover off, or as the global provider stayed "Healthy" through a real outage. Every task LLM attempt now records its outcome through the same policy the Pool uses, keyed by the profile that served it. The LLM recording page also explains an empty list when the `llm_record` toggle is off instead of looking broken.
diff --git a/db/assets.go b/db/assets.go
index d96fec4..7cb2d25 100644
--- a/db/assets.go
+++ b/db/assets.go
@@ -221,7 +221,9 @@ func marshalStringArray(items []string) string {
}
escaped := make([]string, len(items))
for i, s := range items {
- escaped[i] = `"` + strings.ReplaceAll(s, `"`, `\"`) + `"`
+ s = strings.ReplaceAll(s, `\`, `\\`)
+ s = strings.ReplaceAll(s, `"`, `\"`)
+ escaped[i] = `"` + s + `"`
}
return "{" + strings.Join(escaped, ",") + "}"
}
diff --git a/db/assets_test.go b/db/assets_test.go
index 7c5d853..d1f7f24 100644
--- a/db/assets_test.go
+++ b/db/assets_test.go
@@ -879,6 +879,17 @@ func TestMarshalStringArray(t *testing.T) {
if got2 != "{}" {
t.Errorf("empty: %q", got2)
}
+
+ quoted := marshalStringArray([]string{`say "hi"`, `a\b`})
+ if quoted != `{"say \"hi\"","a\\b"}` {
+ t.Errorf("escape: %q", quoted)
+ }
+
+ // A backslash before a quote must not close the element and inject another.
+ injected := marshalStringArray([]string{`x\",evil,\"y`})
+ if strings.Contains(injected, `","evil`) {
+ t.Errorf("backslash-quote split the array: %q", injected)
+ }
}
// =====================================================================