mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-26 01:41:04 +08:00
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.
110 lines
3.9 KiB
Go
110 lines
3.9 KiB
Go
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)
|
|
}
|
|
}
|