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(finding): accept evidence_hint_id 0 and degrade to explicit traffic_refs

lab9f2c290e9fc4
diff --git a/agent/finding_hint_degrade_test.go b/agent/finding_hint_degrade_test.go
new file mode 100644
index 0000000..0ecf724
--- /dev/null
+++ b/agent/finding_hint_degrade_test.go
@@ -0,0 +1,109 @@
+package agent
+
+import (
+ "context"
+ "encoding/json"
+ "strings"
+ "testing"
+
+ "github.com/Autumn-27/artex/db"
+)
+
+// capturingRecorder stands in for the host evidence store and hands the refs it
+// was given straight back, so a test can assert what reached storage.
+type capturingRecorder struct{ got []db.TrafficRef }
+
+func (r *capturingRecorder) Record(_ context.Context, in db.RecordFindingInput, refs []db.TrafficRef) (*db.RecordedFinding, error) {
+ r.got = refs
+ traffic := &db.FindingTraffic{FindingID: 1}
+ for i, ref := range refs {
+ traffic.Bindings = append(traffic.Bindings, db.FindingTrafficBinding{ID: int64(i + 1), FindingID: 1, Role: ref.Role, Note: ref.Note})
+ }
+ return &db.RecordedFinding{FindingID: 1, NodeID: 1, Traffic: traffic}, nil
+}
+
+// Regression for the lab finding where a worker had a real proof traffic id and
+// still could not register the finding, because it sent "evidence_hint_id": 0
+// for the absent optional field. 0 must mean "no hint", never an error.
+func TestReportFindingZeroHintIDIsNotAnError(t *testing.T) {
+ prev := FindingTrafficBindingEnabled()
+ t.Cleanup(func() { SetFindingTrafficBindingEnabled(prev) })
+ SetFindingTrafficBindingEnabled(func() bool { return true })
+
+ d := testDB(t)
+ defer d.Close()
+ task, err := d.CreateTask("zero hint id", "fixture", nil, 0, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer func() {
+ _, _ = d.DeleteFindingsByTask(task.ID)
+ _ = d.DeleteTask(task.ID)
+ }()
+ ts := NewToolSet(nil, "")
+ ts.ts, ts.taskID = d.Exploration(task.ExplorationID), task.ID
+ rec := &capturingRecorder{}
+ ts.SetFindingRecorder(rec)
+
+ body := `{"vulnclass":"SQLI","severity":"high","summary":"zero hint","evidence":"UNION returns rows","evidence_hint_id":0,` +
+ `"traffic_refs":[{"traffic_id":"t-zero-hint","role":"proof"}]}`
+ res, err := ts.addFinding().Call(t.Context(), json.RawMessage(body), nil)
+ if err != nil {
+ t.Fatalf("report_finding returned error: %v", err)
+ }
+ if got := res.Flatten(); !strings.HasPrefix(got, "finding recorded: ") {
+ t.Fatalf("zero hint id rejected: %q", got)
+ }
+ if len(rec.got) != 1 || rec.got[0].TrafficID != "t-zero-hint" {
+ t.Fatalf("explicit proof ref lost: %+v", rec.got)
+ }
+}
+
+// Regression for the same lab run: the model passed the id of a fact node as
+// evidence_hint_id. That must degrade to the explicit traffic_refs the caller
+// already supplied instead of discarding an otherwise complete finding.
+func TestReportFindingNonHintNodeDegradesToExplicitRefs(t *testing.T) {
+ prev := FindingTrafficBindingEnabled()
+ t.Cleanup(func() { SetFindingTrafficBindingEnabled(prev) })
+ SetFindingTrafficBindingEnabled(func() bool { return true })
+
+ d := testDB(t)
+ defer d.Close()
+ task, err := d.CreateTask("fact id as hint", "fixture", nil, 0, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer func() {
+ _, _ = d.DeleteFindingsByTask(task.ID)
+ _ = d.DeleteTask(task.ID)
+ }()
+ exp := d.Exploration(task.ExplorationID)
+
+ // A fact node in the task: exactly what a worker names when it mistakes a
+ // fact for a hint.
+ fact, err := exp.AddNode(db.KindFact, map[string]any{"summary": "captured UNION proof", "detail": "traffic 123"}, 0, "confirmed", "worker", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ rec := &capturingRecorder{}
+ ts := NewToolSet(nil, "")
+ ts.ts, ts.taskID = exp, task.ID
+ ts.SetFindingRecorder(rec)
+
+ body, _ := json.Marshal(map[string]any{
+ "vulnclass": "SQLI", "severity": "high", "summary": "fact id as hint", "evidence": "rows",
+ "evidence_hint_id": fact,
+ "traffic_refs": []map[string]any{{"traffic_id": "t-fact-hint", "role": "proof"}},
+ })
+ res, err := ts.addFinding().Call(t.Context(), json.RawMessage(body), nil)
+ if err != nil {
+ t.Fatalf("report_finding returned error: %v", err)
+ }
+ if got := res.Flatten(); !strings.HasPrefix(got, "finding recorded: ") {
+ t.Fatalf("fact-node hint discarded the finding: %q", got)
+ }
+ if len(rec.got) != 1 || rec.got[0].Role != "proof" || rec.got[0].TrafficID != "t-fact-hint" {
+ t.Fatalf("explicit proof ref did not survive: %+v", rec.got)
+ }
+}
diff --git a/agent/tools.go b/agent/tools.go
index be0613f..440eec2 100644
--- a/agent/tools.go
+++ b/agent/tools.go
@@ -1527,12 +1527,20 @@ func (t *ToolSet) addFinding() actool.CoreTool {
if !findingTrafficBindingEnabled() {
a.TrafficRefs, a.EvidenceHintID = nil, nil
}
- if len(a.EvidenceHintID) > 0 && pid(a.EvidenceHintID) <= 0 {
- return actool.Errorf("evidence_hint_id must be a valid hint node ID; omit it when there is no handover hint"), nil
- }
+ // A model routinely emits "evidence_hint_id": 0 meaning "absent" — the field
+ // is optional, so 0 must mean "no hint", not an error. A hint id that does
+ // not resolve to a local hint node (passing a fact node number is the common
+ // case) must not sink an otherwise complete finding either: when explicit
+ // traffic_refs are present they are sufficient on their own, so degrade to
+ // them and keep the finding. Only a call with neither usable hint nor usable
+ // refs fails.
refs, err := t.findingRefsFromHint(pid(a.EvidenceHintID), a.TrafficRefs)
if err != nil {
- return actool.Errorf(err.Error()), nil
+ if degraded, derr := db.NormalizeTrafficRefs(a.TrafficRefs); derr == nil && len(degraded) > 0 {
+ refs = degraded
+ } else {
+ return actool.Errorf(err.Error()), nil
+ }
}
input := db.RecordFindingInput{TaskID: t.taskID, ExplorationID: t.ts.ID(), IntentID: pid(a.IntentID), VulnClass: a.VulnClass, Name: a.Name, Severity: a.Severity, Summary: a.Summary, Evidence: a.Evidence, Worker: t.worker, AssetIDs: pidList(a.AssetIDs), Counterevidence: a.Counterevidence, ConfidenceRationale: a.ConfidenceRationale}
var recorded *db.RecordedFinding