fix(finding): accept evidence_hint_id 0 and degrade to explicit traffic_refs

report_finding rejected whole findings over the optional evidence_hint_id
field in two ways seen in a live DVWA run:

- the key was present but 0, an error, although the field is optional and
  models emit 0 for "absent" (21 rejections in one task);
- a fact node id was passed instead of a hint id, an error even when the
  caller supplied complete traffic_refs.

Both sink an otherwise provable finding. Now 0 means no hint, and a hint id
that does not resolve to a local hint node degrades to the explicit
traffic_refs. Only a call with no usable hint and no usable refs fails.

Verified end to end: after the fix a worker registered the DVWA UNION SQLi
finding, bound the captured proof exchange itself and quoted the response
body verbatim; the server accepted verification_status=verified (POE L3).
Tests fail on the unfixed tree with the exact production errors.
This commit is contained in:
lab
2026-11-21 14:29:23 +01:00
parent d941a356a5
commit 9f2c290e9f
2 changed files with 121 additions and 4 deletions
+109
View File
@@ -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)
}
}
+12 -4
View File
@@ -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