mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-18 22:20:56 +08:00
Merge pull request #308 from Coff0xc/feat/finding-report-state
feat(findings): report stage separate from triage status
This commit is contained in:
+102
-7
@@ -31,6 +31,7 @@ type DBFinding struct {
|
||||
Worker string
|
||||
AssetIDs []int64
|
||||
Status string
|
||||
ReportState string // none / submitted / accepted / rejected / duplicate; separate from Status
|
||||
PoELevel int // proof-of-exploitation level 0-4 (S1); 0 = none declared
|
||||
VerificationStatus string // verified / unverified / blocked / not_assessed / false_positive
|
||||
VerificationNote string // why the status was reached; empty when verified
|
||||
@@ -65,6 +66,27 @@ func ValidFindingStatus(s string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Finding report stages (findings.report_state). A workflow stage after triage,
|
||||
// not a verdict: a finding can be confirmed and submitted at the same time.
|
||||
// RSI lesson extraction still reads findings.status.
|
||||
const (
|
||||
FindingReportNone = "none"
|
||||
FindingReportSubmitted = "submitted"
|
||||
FindingReportAccepted = "accepted"
|
||||
FindingReportRejected = "rejected"
|
||||
FindingReportDuplicate = "duplicate"
|
||||
)
|
||||
|
||||
// ValidFindingReportState reports whether s is a known report stage.
|
||||
func ValidFindingReportState(s string) bool {
|
||||
switch s {
|
||||
case FindingReportNone, FindingReportSubmitted, FindingReportAccepted,
|
||||
FindingReportRejected, FindingReportDuplicate:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Finding severity levels (findings.severity).
|
||||
const (
|
||||
SeverityCritical = "critical" // Critical
|
||||
@@ -109,7 +131,7 @@ func (d *DB) AddFinding(taskID, nodeID int64, vulnclass, name, severity, summary
|
||||
// findingSelectCols is the column list (with task_description join) every finding
|
||||
// list query selects, so scanFinding stays in sync across callers.
|
||||
const findingSelectCols = `f.id, f.task_id, f.node_id, f.vulnclass, COALESCE(f.name, ''), f.severity, f.summary,
|
||||
f.evidence, f.worker, f.asset_ids, COALESCE(f.status, 'pending'), f.created_at,
|
||||
f.evidence, f.worker, f.asset_ids, COALESCE(f.status, 'pending'), COALESCE(f.report_state, 'none'), f.created_at,
|
||||
COALESCE(t.description, '') AS task_description, f.evidence_version, f.report_evidence_version,
|
||||
f.poe_level, COALESCE(f.verification_status, 'unverified'), COALESCE(f.verification_note, ''),
|
||||
f.counterevidence, f.confidence_rationale,
|
||||
@@ -126,7 +148,7 @@ func scanFindings(rows interface {
|
||||
f := &DBFinding{}
|
||||
var aidsJSON string
|
||||
if err := rows.Scan(&f.ID, &f.TaskID, &f.NodeID, &f.VulnClass, &f.Name, &f.Severity,
|
||||
&f.Summary, &f.Evidence, &f.Worker, &aidsJSON, &f.Status, &f.CreatedAt, &f.TaskDescription, &f.EvidenceVersion, &f.ReportEvidenceVersion, &f.PoELevel, &f.VerificationStatus, &f.VerificationNote, &f.Counterevidence, &f.ConfidenceRationale, &f.TrafficCount); err != nil {
|
||||
&f.Summary, &f.Evidence, &f.Worker, &aidsJSON, &f.Status, &f.ReportState, &f.CreatedAt, &f.TaskDescription, &f.EvidenceVersion, &f.ReportEvidenceVersion, &f.PoELevel, &f.VerificationStatus, &f.VerificationNote, &f.Counterevidence, &f.ConfidenceRationale, &f.TrafficCount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = json.Unmarshal([]byte(aidsJSON), &f.AssetIDs)
|
||||
@@ -160,6 +182,7 @@ func (d *DB) ListFindings(limit int) ([]*DBFinding, error) {
|
||||
type FindingFilter struct {
|
||||
Severity string // high | medium | low
|
||||
Status string // pending | false_positive | ignored | resolved
|
||||
ReportState string // none | submitted | accepted | rejected | duplicate
|
||||
VerificationStatus string // verified | unverified | blocked | not_assessed | false_positive
|
||||
VulnClass string
|
||||
TaskID string // task id (in string form; empty/invalid = do not filter by task)
|
||||
@@ -197,6 +220,7 @@ func (f FindingFilter) where() (string, []any) {
|
||||
}
|
||||
add("severity", f.Severity)
|
||||
add("status", f.Status)
|
||||
add("report_state", f.ReportState)
|
||||
add("verification_status", f.VerificationStatus)
|
||||
add("vulnclass", f.VulnClass)
|
||||
// task_id is a bigint column, compared as an integer (it cannot go through
|
||||
@@ -528,7 +552,7 @@ func (d *DB) ListFindingsForExport(f FindingFilter, ids []int64) ([]*DBFinding,
|
||||
f := &DBFinding{}
|
||||
var aidsJSON string
|
||||
if err := rows.Scan(&f.ID, &f.TaskID, &f.NodeID, &f.VulnClass, &f.Name, &f.Severity,
|
||||
&f.Summary, &f.Evidence, &f.Worker, &aidsJSON, &f.Status, &f.CreatedAt,
|
||||
&f.Summary, &f.Evidence, &f.Worker, &aidsJSON, &f.Status, &f.ReportState, &f.CreatedAt,
|
||||
&f.TaskDescription, &f.EvidenceVersion, &f.ReportEvidenceVersion, &f.PoELevel, &f.VerificationStatus, &f.VerificationNote, &f.Counterevidence, &f.ConfidenceRationale, &f.TrafficCount, &f.Report); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -544,6 +568,8 @@ func (d *DB) ListFindingsForExport(f FindingFilter, ids []int64) ([]*DBFinding,
|
||||
type FindingStats struct {
|
||||
Total int `json:"total"`
|
||||
Pending int `json:"pending"`
|
||||
Submitted int `json:"submitted"`
|
||||
Accepted int `json:"accepted"`
|
||||
Critical int `json:"critical"`
|
||||
High int `json:"high"`
|
||||
Medium int `json:"medium"`
|
||||
@@ -563,18 +589,20 @@ type FindingTaskOption struct {
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// FindingStats returns whole-table counts (by severity + pending) and the sorted
|
||||
// set of distinct vuln classes.
|
||||
// FindingStats returns whole-table counts (by severity, pending, and report
|
||||
// stage) and the sorted set of distinct vuln classes.
|
||||
func (d *DB) FindingStats() (*FindingStats, error) {
|
||||
st := &FindingStats{VulnClasses: []string{}, Tasks: []FindingTaskOption{}}
|
||||
err := d.QueryRow(`SELECT
|
||||
COUNT(*),
|
||||
COUNT(*) FILTER (WHERE status = 'pending'),
|
||||
COUNT(*) FILTER (WHERE report_state = 'submitted'),
|
||||
COUNT(*) FILTER (WHERE report_state = 'accepted'),
|
||||
COUNT(*) FILTER (WHERE severity = 'critical'),
|
||||
COUNT(*) FILTER (WHERE severity = 'high'),
|
||||
COUNT(*) FILTER (WHERE severity = 'medium'),
|
||||
COUNT(*) FILTER (WHERE severity = 'low')
|
||||
FROM findings`).Scan(&st.Total, &st.Pending, &st.Critical, &st.High, &st.Medium, &st.Low)
|
||||
FROM findings`).Scan(&st.Total, &st.Pending, &st.Submitted, &st.Accepted, &st.Critical, &st.High, &st.Medium, &st.Low)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -629,6 +657,8 @@ func (d *DB) FindingStats() (*FindingStats, error) {
|
||||
cold := aggregate.FindingStats
|
||||
st.Total += cold.Total
|
||||
st.Pending += cold.Pending
|
||||
st.Submitted += cold.Submitted
|
||||
st.Accepted += cold.Accepted
|
||||
st.Critical += cold.Critical
|
||||
st.High += cold.High
|
||||
st.Medium += cold.Medium
|
||||
@@ -658,7 +688,7 @@ func (d *DB) GetFinding(id int64) (*DBFinding, error) {
|
||||
LEFT JOIN tasks t ON f.task_id = t.id
|
||||
WHERE f.id = $1`, id).Scan(
|
||||
&f.ID, &f.TaskID, &f.NodeID, &f.VulnClass, &f.Name, &f.Severity,
|
||||
&f.Summary, &f.Evidence, &f.Worker, &aidsJSON, &f.Status, &f.CreatedAt,
|
||||
&f.Summary, &f.Evidence, &f.Worker, &aidsJSON, &f.Status, &f.ReportState, &f.CreatedAt,
|
||||
&f.TaskDescription, &f.EvidenceVersion, &f.ReportEvidenceVersion, &f.PoELevel, &f.VerificationStatus, &f.VerificationNote, &f.Counterevidence, &f.ConfidenceRationale, &f.TrafficCount, &f.Report)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -723,6 +753,71 @@ func (d *DB) SetFindingStatus(id int64, status string) (int64, error) {
|
||||
return d.setFindingCol(id, "status", "status", status)
|
||||
}
|
||||
|
||||
// SetFindingReportState updates one finding's report stage and mirrors it onto
|
||||
// the originating exploration node's payload under "report_state". It does not
|
||||
// register a status-change notification: report_state is a workflow stage, not
|
||||
// a triage verdict. Returns rows affected.
|
||||
func (d *DB) SetFindingReportState(id int64, state string) (int64, error) {
|
||||
return d.setFindingCol(id, "report_state", "report_state", state)
|
||||
}
|
||||
|
||||
// FindingReportStateBatchResult is one id's outcome in a bulk report-stage update.
|
||||
type FindingReportStateBatchResult struct {
|
||||
ID int64 `json:"id"`
|
||||
From string `json:"from,omitempty"`
|
||||
Found bool `json:"found"`
|
||||
Changed bool `json:"changed"`
|
||||
}
|
||||
|
||||
// SetFindingReportStates updates several findings to the same report stage in
|
||||
// one transaction. Unknown ids come back as found=false instead of hiding the
|
||||
// others; a database error rolls the whole batch back. No notification event
|
||||
// is written — status-change pushes stay on findings.status.
|
||||
func (d *DB) SetFindingReportStates(ctx context.Context, ids []int64, state string) ([]FindingReportStateBatchResult, error) {
|
||||
out := make([]FindingReportStateBatchResult, 0, len(ids))
|
||||
err := d.WithEvidenceTx(ctx, func(tx *sql.Tx) error {
|
||||
for _, id := range ids {
|
||||
from, found, changed, err := setFindingReportStateTx(ctx, tx, id, state)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out = append(out, FindingReportStateBatchResult{ID: id, From: from, Found: found, Changed: changed})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func setFindingReportStateTx(ctx context.Context, tx *sql.Tx, id int64, state string) (from string, found bool, changed bool, err error) {
|
||||
var nodeID sql.NullInt64
|
||||
scanErr := tx.QueryRowContext(ctx, `SELECT COALESCE(report_state,'none'), node_id
|
||||
FROM findings WHERE id=$1 FOR UPDATE`, id).Scan(&from, &nodeID)
|
||||
if scanErr == sql.ErrNoRows {
|
||||
return "", false, false, nil
|
||||
}
|
||||
if scanErr != nil {
|
||||
return "", false, false, scanErr
|
||||
}
|
||||
found = true
|
||||
if from == state {
|
||||
return from, true, false, nil
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx, `UPDATE findings SET report_state=$2 WHERE id=$1`, id, state); err != nil {
|
||||
return from, true, false, err
|
||||
}
|
||||
if nodeID.Valid {
|
||||
if _, err := tx.ExecContext(ctx, `UPDATE exploration_nodes
|
||||
SET payload = jsonb_set(payload, '{report_state}', to_jsonb($1::text))
|
||||
WHERE id = $2`, state, nodeID.Int64); err != nil {
|
||||
return from, true, false, err
|
||||
}
|
||||
}
|
||||
return from, true, true, nil
|
||||
}
|
||||
|
||||
// SetFindingReportByNodeID sets the Markdown report on the standalone finding row
|
||||
// whose node_id matches — report_finding returns that node id, so an agent tool
|
||||
// can address the finding it just created. Returns rows affected (0 when no row).
|
||||
|
||||
@@ -13,6 +13,25 @@ import (
|
||||
|
||||
// TestDeleteFinding verifies that deleting a finding removes both the findings
|
||||
// row and its originating exploration node (kind='finding').
|
||||
func TestValidFindingReportState(t *testing.T) {
|
||||
for _, s := range []string{
|
||||
FindingReportNone, FindingReportSubmitted, FindingReportAccepted,
|
||||
FindingReportRejected, FindingReportDuplicate,
|
||||
} {
|
||||
if !ValidFindingReportState(s) {
|
||||
t.Fatalf("%q should be valid", s)
|
||||
}
|
||||
}
|
||||
for _, s := range []string{"", "confirmed", "pending", "SUBMITTED", "submitted "} {
|
||||
if ValidFindingReportState(s) {
|
||||
t.Fatalf("%q should be invalid", s)
|
||||
}
|
||||
}
|
||||
if ValidFindingStatus(FindingReportSubmitted) {
|
||||
t.Fatal("submitted must not be a triage status")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteFinding(t *testing.T) {
|
||||
d, err := Open(testDSN(t))
|
||||
if err != nil {
|
||||
@@ -122,6 +141,115 @@ func TestSetFindingStatusMirrorsNodePayload(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindingReportState(t *testing.T) {
|
||||
d, err := Open(testDSN(t))
|
||||
if err != nil {
|
||||
t.Skipf("postgres unavailable (%v) — skipping", err)
|
||||
}
|
||||
defer d.Close()
|
||||
|
||||
tk, err := d.CreateTask("finding report state", "goal", nil, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer d.DeleteTask(tk.ID)
|
||||
|
||||
es := d.Exploration(tk.ExplorationID)
|
||||
nodeID, err := es.AddNode(KindFinding, map[string]any{"summary": "x", "severity": "high"}, 5, "confirmed", "worker", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fid, err := d.AddFinding(tk.ID, nodeID, "XSS", "reflected XSS", "high", "summary", "poc", "worker", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, err := d.AddFinding(tk.ID, 0, "XSS", "other", "low", "summary", "poc", "worker", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { d.Exec(`DELETE FROM notification_events WHERE finding_id IN ($1,$2)`, fid, second) })
|
||||
|
||||
one, err := d.GetFinding(fid)
|
||||
if err != nil || one == nil || one.ReportState != FindingReportNone {
|
||||
t.Fatalf("new finding report_state: %+v err=%v", one, err)
|
||||
}
|
||||
|
||||
n, err := d.SetFindingReportState(fid, FindingReportSubmitted)
|
||||
if err != nil || n != 1 {
|
||||
t.Fatalf("SetFindingReportState: n=%d err=%v", n, err)
|
||||
}
|
||||
one, _ = d.GetFinding(fid)
|
||||
if one.ReportState != FindingReportSubmitted {
|
||||
t.Fatalf("report_state=%q", one.ReportState)
|
||||
}
|
||||
if one.Status != FindingPending {
|
||||
t.Fatalf("triage status changed: %q", one.Status)
|
||||
}
|
||||
|
||||
var payload []byte
|
||||
if err := d.QueryRow(`SELECT payload FROM exploration_nodes WHERE id=$1`, nodeID).Scan(&payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var p map[string]any
|
||||
if err := json.Unmarshal(payload, &p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p["report_state"] != FindingReportSubmitted {
|
||||
t.Fatalf("payload report_state=%v", p["report_state"])
|
||||
}
|
||||
|
||||
listed, total, err := d.ListFindingsPage(FindingFilter{TaskID: fmt.Sprintf("%d", tk.ID), ReportState: FindingReportSubmitted}, 1, 20)
|
||||
if err != nil || total != 1 || len(listed) != 1 || listed[0].ID != fid {
|
||||
t.Fatalf("filter submitted: total=%d listed=%d err=%v", total, len(listed), err)
|
||||
}
|
||||
|
||||
st, err := d.FindingStats()
|
||||
if err != nil || st.Submitted < 1 {
|
||||
t.Fatalf("stats submitted undercount: %+v err=%v", st, err)
|
||||
}
|
||||
|
||||
const missingID = int64(999999999)
|
||||
results, err := d.SetFindingReportStates(context.Background(), []int64{fid, second, missingID}, FindingReportAccepted)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(results) != 3 {
|
||||
t.Fatalf("want 3 results, got %d", len(results))
|
||||
}
|
||||
if !results[0].Found || !results[0].Changed || results[0].From != FindingReportSubmitted {
|
||||
t.Fatalf("first: %+v", results[0])
|
||||
}
|
||||
if !results[1].Found || !results[1].Changed || results[1].From != FindingReportNone {
|
||||
t.Fatalf("second: %+v", results[1])
|
||||
}
|
||||
if results[2].Found || results[2].Changed {
|
||||
t.Fatalf("missing: %+v", results[2])
|
||||
}
|
||||
|
||||
again, err := d.SetFindingReportStates(context.Background(), []int64{fid}, FindingReportAccepted)
|
||||
if err != nil || len(again) != 1 || again[0].Changed {
|
||||
t.Fatalf("noop batch: %v %v", again, err)
|
||||
}
|
||||
|
||||
var events int
|
||||
if err := d.QueryRow(`SELECT count(*) FROM notification_events WHERE finding_id IN ($1,$2)`, fid, second).Scan(&events); err != nil || events != 0 {
|
||||
t.Fatalf("report_state must not write notification_events: %d (%v)", events, err)
|
||||
}
|
||||
|
||||
one, _ = d.GetFinding(fid)
|
||||
if one.Status != FindingPending {
|
||||
t.Fatalf("bulk report_state mutated triage: %q", one.Status)
|
||||
}
|
||||
if one.ReportState != FindingReportAccepted {
|
||||
t.Fatalf("bulk report_state=%q", one.ReportState)
|
||||
}
|
||||
|
||||
st, err = d.FindingStats()
|
||||
if err != nil || st.Accepted < 2 {
|
||||
t.Fatalf("stats accepted undercount: %+v err=%v", st, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFindingsPageAndStats exercises ListFindingsPage (filter/sort/paging) and
|
||||
// FindingStats against the live dev PG. It tags its rows with a unique vulnclass
|
||||
// so assertions are isolated from any pre-existing data, and cleans up after.
|
||||
@@ -226,6 +354,9 @@ func TestFindingsPageAndStats(t *testing.T) {
|
||||
if one == nil || one.ID != ids[0] || one.Severity != "critical" || one.Name != "Critical Vulnerability Title" {
|
||||
t.Fatalf("GetFinding mismatch: %+v", one)
|
||||
}
|
||||
if one.ReportState != FindingReportNone {
|
||||
t.Fatalf("new finding report_state should be none, got %q", one.ReportState)
|
||||
}
|
||||
if one.Report != "" {
|
||||
t.Fatalf("new finding report should be empty, got %q", one.Report)
|
||||
}
|
||||
|
||||
+2
-2
@@ -137,9 +137,9 @@ func assertEmbeddedApplied(t *testing.T, d *DB) []appliedMigration {
|
||||
version int
|
||||
name string
|
||||
}{{1, llmRecordsMigration}, {2, llmUsageMigration}, {3, "0003_task_scope_icp_index.sql"}, {4, "0004_llm_usage_ts_index.sql"},
|
||||
{5, "0005_traffic_rewrite_rules.sql"}, {6, "0006_activity_outbox.sql"}}
|
||||
{5, "0005_traffic_rewrite_rules.sql"}, {6, "0006_activity_outbox.sql"}, {7, "0007_finding_report_state.sql"}}
|
||||
if len(applied) != len(want) {
|
||||
t.Fatalf("schema_migrations = %+v, want versions 1 to 6", applied)
|
||||
t.Fatalf("schema_migrations = %+v, want versions 1 to 7", applied)
|
||||
}
|
||||
for i, w := range want {
|
||||
content, err := fs.ReadFile(migrationsFS(), w.name)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Report stage on findings, separate from triage status. Existing rows stay
|
||||
-- 'none'. Values are validated server-side (no CHECK): none / submitted /
|
||||
-- accepted / rejected / duplicate. RSI lessons still read findings.status.
|
||||
ALTER TABLE findings ADD COLUMN IF NOT EXISTS report_state TEXT NOT NULL DEFAULT 'none';
|
||||
CREATE INDEX IF NOT EXISTS idx_findings_report_state ON findings (report_state, created_at DESC);
|
||||
@@ -1256,6 +1256,11 @@ ALTER TABLE findings ADD COLUMN IF NOT EXISTS verification_note TEXT NOT NULL DE
|
||||
-- tested and did not work; confidence_rationale is why the conclusion holds.
|
||||
ALTER TABLE findings ADD COLUMN IF NOT EXISTS counterevidence TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE findings ADD COLUMN IF NOT EXISTS confidence_rationale TEXT NOT NULL DEFAULT '';
|
||||
-- Report stage after triage (none / submitted / accepted / rejected / duplicate).
|
||||
-- Separate from status so a finding can be confirmed and submitted at once; RSI
|
||||
-- lessons still read status. Server whitelist, no CHECK (same as status).
|
||||
ALTER TABLE findings ADD COLUMN IF NOT EXISTS report_state TEXT NOT NULL DEFAULT 'none';
|
||||
CREATE INDEX IF NOT EXISTS idx_findings_report_state ON findings (report_state, created_at DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS traffic_evidence_snapshots (
|
||||
id TEXT PRIMARY KEY,
|
||||
|
||||
@@ -770,6 +770,8 @@ FROM skill_usage WHERE (task_id=$1 OR exploration_id=$2) AND NOT found GROUP BY
|
||||
{"findings", `SELECT COALESCE(jsonb_object_agg(name,n),'{}'::jsonb) FROM (SELECT COALESCE(NULLIF(severity,''),'unknown') name,count(*) n FROM findings WHERE task_id=$1 GROUP BY severity) x`, []any{taskID}},
|
||||
{"finding_stats", `SELECT jsonb_build_object(
|
||||
'total',count(*),'pending',count(*) FILTER (WHERE status='pending'),
|
||||
'submitted',count(*) FILTER (WHERE report_state='submitted'),
|
||||
'accepted',count(*) FILTER (WHERE report_state='accepted'),
|
||||
'critical',count(*) FILTER (WHERE severity='critical'),'high',count(*) FILTER (WHERE severity='high'),
|
||||
'medium',count(*) FILTER (WHERE severity='medium'),'low',count(*) FILTER (WHERE severity='low'),
|
||||
'vulnclasses',COALESCE(jsonb_agg(DISTINCT vulnclass) FILTER (WHERE vulnclass<>''),'[]'::jsonb))
|
||||
|
||||
+32
-20
@@ -361,28 +361,40 @@ func rowExists(tx *sql.Tx, table string, id int64) bool {
|
||||
return exists
|
||||
}
|
||||
|
||||
func insertArchiveRows(tx *sql.Tx, table string, raw json.RawMessage) error {
|
||||
// json_populate_recordset inserts NULL for absent columns, bypassing SQL
|
||||
// defaults. Preserve compatibility with v3 archives predating side memory.
|
||||
if (table == "side_question_sessions" || table == "side_question_requests") && len(raw) > 0 {
|
||||
var rows []map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &rows); err != nil {
|
||||
return err
|
||||
}
|
||||
field := "memory"
|
||||
if table == "side_question_requests" {
|
||||
field = "context_info"
|
||||
}
|
||||
for _, row := range rows {
|
||||
// archiveDefaults are the columns that did not exist when older archives were
|
||||
// written. json_populate_recordset inserts NULL for an absent key, bypassing the
|
||||
// SQL default, and a NOT NULL column then rejects the whole restore.
|
||||
var archiveDefaults = map[string]map[string]string{
|
||||
"side_question_sessions": {"memory": `{}`},
|
||||
"side_question_requests": {"context_info": `{}`},
|
||||
"findings": {"report_state": `"none"`},
|
||||
}
|
||||
|
||||
// fillArchiveDefaults restores the default of a column an older archive
|
||||
// predates, so a restore keeps working across schema additions.
|
||||
func fillArchiveDefaults(table string, raw json.RawMessage) (json.RawMessage, error) {
|
||||
defaults, ok := archiveDefaults[table]
|
||||
if !ok || len(raw) == 0 {
|
||||
return raw, nil
|
||||
}
|
||||
var rows []map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &rows); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, row := range rows {
|
||||
for field, def := range defaults {
|
||||
if len(row[field]) == 0 || string(row[field]) == "null" {
|
||||
row[field] = json.RawMessage(`{}`)
|
||||
row[field] = json.RawMessage(def)
|
||||
}
|
||||
}
|
||||
var err error
|
||||
raw, err = json.Marshal(rows)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return json.Marshal(rows)
|
||||
}
|
||||
|
||||
func insertArchiveRows(tx *sql.Tx, table string, raw json.RawMessage) error {
|
||||
raw, err := fillArchiveDefaults(table, raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
allowed := map[string]bool{
|
||||
"exploration_nodes": true, "exploration_edges": true, "exploration_anchors": true,
|
||||
@@ -396,7 +408,7 @@ func insertArchiveRows(tx *sql.Tx, table string, raw json.RawMessage) error {
|
||||
if rawRowCount(raw) == 0 {
|
||||
return nil
|
||||
}
|
||||
_, err := tx.Exec(`INSERT INTO `+table+` SELECT * FROM json_populate_recordset(NULL::`+table+`,$1::json)`, string(raw))
|
||||
_, err = tx.Exec(`INSERT INTO `+table+` SELECT * FROM json_populate_recordset(NULL::`+table+`,$1::json)`, string(raw))
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -486,3 +486,34 @@ func assertArchiveGlobalStats(t *testing.T, d *DB, profileName, skillName, toolN
|
||||
t.Fatalf("archive finding class %q missing", vulnclass)
|
||||
}
|
||||
}
|
||||
|
||||
// An archive written before report_state existed restores with the column's
|
||||
// default instead of failing on the NOT NULL constraint.
|
||||
func TestFillArchiveDefaults(t *testing.T) {
|
||||
raw := json.RawMessage(`[{"id":1,"summary":"old"},{"id":2,"report_state":null},{"id":3,"report_state":"submitted"}]`)
|
||||
out, err := fillArchiveDefaults("findings", raw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var rows []map[string]json.RawMessage
|
||||
if err := json.Unmarshal(out, &rows); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{`"none"`, `"none"`, `"submitted"`}
|
||||
for i, row := range rows {
|
||||
if string(row["report_state"]) != want[i] {
|
||||
t.Fatalf("row %d report_state=%s, want %s", i, row["report_state"], want[i])
|
||||
}
|
||||
}
|
||||
|
||||
// Side memory keeps its own default, and other tables pass through.
|
||||
out, err = fillArchiveDefaults("side_question_sessions", json.RawMessage(`[{"id":1}]`))
|
||||
if err != nil || !strings.Contains(string(out), `"memory":{}`) {
|
||||
t.Fatalf("side memory default missing: %s err=%v", out, err)
|
||||
}
|
||||
in := json.RawMessage(`[{"id":1}]`)
|
||||
out, err = fillArchiveDefaults("activity", in)
|
||||
if err != nil || string(out) != string(in) {
|
||||
t.Fatalf("activity changed: %s err=%v", out, err)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -70,6 +70,7 @@ func FindingsMarkdown(fs []*db.DBFinding, generatedAt time.Time) string {
|
||||
fmt.Fprintf(&b, "- **Class**: %s\n", f.VulnClass)
|
||||
}
|
||||
fmt.Fprintf(&b, "- **Status**: %s\n", nz(f.Status, "pending"))
|
||||
fmt.Fprintf(&b, "- **Report stage**: %s\n", nz(f.ReportState, "none"))
|
||||
if desc := strings.TrimSpace(f.TaskDescription); desc != "" {
|
||||
fmt.Fprintf(&b, "- **Task**: %s\n", desc)
|
||||
}
|
||||
@@ -99,6 +100,7 @@ func SingleFindingMarkdown(f *db.DBFinding, generatedAt time.Time) string {
|
||||
}
|
||||
fmt.Fprintf(&b, "- **Severity**: %s\n", nz(f.Severity, "info"))
|
||||
fmt.Fprintf(&b, "- **Status**: %s\n", nz(f.Status, "pending"))
|
||||
fmt.Fprintf(&b, "- **Report stage**: %s\n", nz(f.ReportState, "none"))
|
||||
if desc := strings.TrimSpace(f.TaskDescription); desc != "" {
|
||||
fmt.Fprintf(&b, "- **Task**: %s\n", desc)
|
||||
}
|
||||
@@ -148,7 +150,7 @@ func FindingsCSV(fs []*db.DBFinding) []byte {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("\xEF\xBB\xBF") // UTF-8 BOM
|
||||
w := csv.NewWriter(&buf)
|
||||
_ = w.Write([]string{"ID", "Name", "Class", "Severity", "Status", "Task", "Found At", "Summary", "Traffic Evidence Count", "Traffic Evidence IDs"})
|
||||
_ = w.Write([]string{"ID", "Name", "Class", "Severity", "Status", "Report Stage", "Task", "Found At", "Summary", "Traffic Evidence Count", "Traffic Evidence IDs"})
|
||||
for _, f := range items {
|
||||
_ = w.Write([]string{
|
||||
fmt.Sprintf("%d", f.ID),
|
||||
@@ -156,6 +158,7 @@ func FindingsCSV(fs []*db.DBFinding) []byte {
|
||||
f.VulnClass,
|
||||
nz(f.Severity, "info"),
|
||||
nz(f.Status, "pending"),
|
||||
nz(f.ReportState, "none"),
|
||||
f.TaskDescription,
|
||||
f.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
strings.TrimSpace(f.Summary),
|
||||
|
||||
@@ -32,3 +32,37 @@ func TestBulkFindingStatusValidation(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeFindingIDs(t *testing.T) {
|
||||
got := normalizeFindingIDs([]int64{0, -1, 2, 2, 3, 4}, 2)
|
||||
if len(got) != 2 || got[0] != 2 || got[1] != 3 {
|
||||
t.Fatalf("got %v, want [2 3]", got)
|
||||
}
|
||||
if got := normalizeFindingIDs(nil, 500); len(got) != 0 {
|
||||
t.Fatalf("empty input: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBulkFindingReportStateValidation(t *testing.T) {
|
||||
s := &Server{m: &Manager{}}
|
||||
cases := []struct {
|
||||
name string
|
||||
body string
|
||||
want int
|
||||
}{
|
||||
{"bad json", `{`, http.StatusBadRequest},
|
||||
{"unknown state", `{"ids":[1],"report_state":"confirmed"}`, http.StatusBadRequest},
|
||||
{"empty ids", `{"ids":[],"report_state":"submitted"}`, http.StatusBadRequest},
|
||||
{"non-positive ids", `{"ids":[0,-3],"report_state":"submitted"}`, http.StatusBadRequest},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/exploration/findings/bulk-report-state", strings.NewReader(tc.body))
|
||||
s.bulkPatchFindingReportState(rec, req)
|
||||
if rec.Code != tc.want {
|
||||
t.Fatalf("status %d, want %d: %s", rec.Code, tc.want, rec.Body.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+23
-17
@@ -327,15 +327,16 @@ type FindingDTO struct {
|
||||
Counterevidence string `json:"counterevidence,omitempty"` // what was tested and did not work; optional
|
||||
ConfidenceRationale string `json:"confidence_rationale,omitempty"` // why the conclusion holds; optional
|
||||
|
||||
ID string `json:"id"`
|
||||
FindingID string `json:"finding_id,omitempty"` // standalone findings-table id — the handle for status updates
|
||||
VulnClass string `json:"vulnclass"`
|
||||
Name string `json:"name,omitempty"` // vulnerability name; the frontend falls back to displaying vulnclass when empty
|
||||
Severity string `json:"severity"` // critical | high | medium | low
|
||||
Status string `json:"status"` // pending | in_progress | confirmed | resolved | fixed | false_positive | ignored | duplicate | risk_accepted
|
||||
Summary string `json:"summary"`
|
||||
Evidence string `json:"evidence"`
|
||||
Report string `json:"report,omitempty"` // detailed report (Markdown); returned only by the detail endpoint, empty in lists
|
||||
ID string `json:"id"`
|
||||
FindingID string `json:"finding_id,omitempty"` // standalone findings-table id — the handle for status updates
|
||||
VulnClass string `json:"vulnclass"`
|
||||
Name string `json:"name,omitempty"` // vulnerability name; the frontend falls back to displaying vulnclass when empty
|
||||
Severity string `json:"severity"` // critical | high | medium | low
|
||||
Status string `json:"status"` // pending | in_progress | confirmed | resolved | fixed | false_positive | ignored | duplicate | risk_accepted
|
||||
ReportState string `json:"report_state"` // none | submitted | accepted | rejected | duplicate; workflow stage, not a triage verdict
|
||||
Summary string `json:"summary"`
|
||||
Evidence string `json:"evidence"`
|
||||
Report string `json:"report,omitempty"` // detailed report (Markdown); returned only by the detail endpoint, empty in lists
|
||||
|
||||
IntentID string `json:"intent_id,omitempty"`
|
||||
ParamID string `json:"param_id,omitempty"`
|
||||
@@ -461,6 +462,10 @@ func findingFromDB(f *db.DBFinding, assets map[int64]*db.Asset) FindingDTO {
|
||||
if status == "" {
|
||||
status = db.FindingPending
|
||||
}
|
||||
reportState := f.ReportState
|
||||
if reportState == "" {
|
||||
reportState = db.FindingReportNone
|
||||
}
|
||||
d := FindingDTO{
|
||||
ID: i64s(f.ID),
|
||||
FindingID: i64s(f.ID),
|
||||
@@ -468,14 +473,15 @@ func findingFromDB(f *db.DBFinding, assets map[int64]*db.Asset) FindingDTO {
|
||||
ReportStale: f.Report != "" && f.EvidenceVersion != f.ReportEvidenceVersion, TrafficBindings: f.TrafficBindings,
|
||||
PoELevel: f.PoELevel, VerificationStatus: f.VerificationStatus, VerificationNote: f.VerificationNote,
|
||||
Counterevidence: f.Counterevidence, ConfidenceRationale: f.ConfidenceRationale,
|
||||
VulnClass: f.VulnClass,
|
||||
Name: f.Name,
|
||||
Severity: f.Severity,
|
||||
Status: status,
|
||||
Summary: f.Summary,
|
||||
Evidence: f.Evidence,
|
||||
Report: f.Report,
|
||||
TS: rfc3339(f.CreatedAt),
|
||||
VulnClass: f.VulnClass,
|
||||
Name: f.Name,
|
||||
Severity: f.Severity,
|
||||
Status: status,
|
||||
ReportState: reportState,
|
||||
Summary: f.Summary,
|
||||
Evidence: f.Evidence,
|
||||
Report: f.Report,
|
||||
TS: rfc3339(f.CreatedAt),
|
||||
}
|
||||
d.Assets = findingAssetDTOs(f.AssetIDs, assets)
|
||||
if f.TaskID != nil {
|
||||
|
||||
@@ -26,6 +26,17 @@ func TestFindingDTOReasoningFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindingDTOReportState(t *testing.T) {
|
||||
raw, _ := json.Marshal(findingFromDB(&db.DBFinding{ID: 1}, nil))
|
||||
if !strings.Contains(string(raw), `"report_state":"none"`) {
|
||||
t.Fatalf("empty report_state should serialize as none: %s", raw)
|
||||
}
|
||||
d := findingFromDB(&db.DBFinding{ID: 2, ReportState: db.FindingReportSubmitted}, nil)
|
||||
if d.ReportState != db.FindingReportSubmitted {
|
||||
t.Fatalf("report_state lost: %q", d.ReportState)
|
||||
}
|
||||
}
|
||||
|
||||
// PG: the detail endpoint returns the stored fields, and the report_finding
|
||||
// schema upgrade adds both properties to an existing (customized) row without
|
||||
// overwriting it.
|
||||
|
||||
@@ -31,6 +31,7 @@ func findingFilterFromQuery(q url.Values) db.FindingFilter {
|
||||
return db.FindingFilter{
|
||||
Severity: normFilter(q.Get("severity")),
|
||||
Status: normFilter(q.Get("status")),
|
||||
ReportState: normFilter(q.Get("report_state")),
|
||||
VerificationStatus: normFilter(q.Get("verification_status")),
|
||||
VulnClass: normFilter(q.Get("vulnclass")),
|
||||
// task_id (independent of the task param, which switches to the per-task-node branch): filters the global table by task.
|
||||
|
||||
+80
-19
@@ -848,6 +848,7 @@ func (s *Server) Handler() http.Handler {
|
||||
mux.HandleFunc("POST /api/exploration/findings/{id}/retests", s.startFindingRetest)
|
||||
mux.HandleFunc("PATCH /api/exploration/findings/{id}", s.patchFinding)
|
||||
mux.HandleFunc("POST /api/exploration/findings/bulk-status", s.bulkPatchFindingStatus)
|
||||
mux.HandleFunc("POST /api/exploration/findings/bulk-report-state", s.bulkPatchFindingReportState)
|
||||
mux.HandleFunc("DELETE /api/exploration/findings/{id}", s.deleteFinding)
|
||||
mux.HandleFunc("GET /api/exploration/intents", s.intents)
|
||||
mux.HandleFunc("GET /api/exploration/graph", s.explorationGraph)
|
||||
@@ -2364,7 +2365,7 @@ func (s *Server) getFinding(w http.ResponseWriter, r *http.Request) {
|
||||
// format = md-single (one combined .md) | md-zip (one .md per vulnerability, zipped)
|
||||
// | csv | json
|
||||
// ids = comma-separated finding ids (required when scope=selected)
|
||||
// Filter params severity/status/vulnclass/task_id/q/sort match the list endpoint (used when scope=filtered).
|
||||
// Filter params severity/status/report_state/vulnclass/task_id/q/sort match the list endpoint (used when scope=filtered).
|
||||
func (s *Server) findingsExport(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
scope := q.Get("scope")
|
||||
@@ -2529,17 +2530,18 @@ func (s *Server) patchFinding(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
var body struct {
|
||||
Status *string `json:"status"`
|
||||
Severity *string `json:"severity"`
|
||||
Name *string `json:"name"`
|
||||
VulnClass *string `json:"vulnclass"`
|
||||
Status *string `json:"status"`
|
||||
ReportState *string `json:"report_state"`
|
||||
Severity *string `json:"severity"`
|
||||
Name *string `json:"name"`
|
||||
VulnClass *string `json:"vulnclass"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
writeErr(w, 400, "bad json: "+err.Error())
|
||||
return
|
||||
}
|
||||
if body.Status == nil && body.Severity == nil && body.Name == nil && body.VulnClass == nil {
|
||||
writeErr(w, 400, "nothing to update: provide status/severity/name/vulnclass")
|
||||
if body.Status == nil && body.ReportState == nil && body.Severity == nil && body.Name == nil && body.VulnClass == nil {
|
||||
writeErr(w, 400, "nothing to update: provide status/severity/name/vulnclass/report_state")
|
||||
return
|
||||
}
|
||||
if body.Status != nil {
|
||||
@@ -2563,6 +2565,21 @@ func (s *Server) patchFinding(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("[notify] status-change event not registered finding=%d %s→%s (status was updated)", id, from, *body.Status)
|
||||
}
|
||||
}
|
||||
if body.ReportState != nil {
|
||||
if !db.ValidFindingReportState(*body.ReportState) {
|
||||
writeErr(w, 400, "bad report_state: "+*body.ReportState)
|
||||
return
|
||||
}
|
||||
n, err := s.m.pg.SetFindingReportState(id, *body.ReportState)
|
||||
if err != nil {
|
||||
writeErr(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
writeErr(w, 404, "finding not found")
|
||||
return
|
||||
}
|
||||
}
|
||||
if body.Severity != nil {
|
||||
if !db.ValidSeverity(*body.Severity) {
|
||||
writeErr(w, 400, "bad severity: "+*body.Severity)
|
||||
@@ -2634,18 +2651,7 @@ func (s *Server) bulkPatchFindingStatus(w http.ResponseWriter, r *http.Request)
|
||||
writeErr(w, 400, "bad status: "+body.Status)
|
||||
return
|
||||
}
|
||||
seen := make(map[int64]bool, len(body.IDs))
|
||||
ids := make([]int64, 0, len(body.IDs))
|
||||
for _, id := range body.IDs {
|
||||
if id <= 0 || seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
ids = append(ids, id)
|
||||
if len(ids) == maxBulkFindingStatus {
|
||||
break
|
||||
}
|
||||
}
|
||||
ids := normalizeFindingIDs(body.IDs, maxBulkFindingStatus)
|
||||
if len(ids) == 0 {
|
||||
writeErr(w, 400, "no finding ids")
|
||||
return
|
||||
@@ -2667,6 +2673,61 @@ func (s *Server) bulkPatchFindingStatus(w http.ResponseWriter, r *http.Request)
|
||||
writeJSON(w, 200, map[string]any{"updated": updated, "missing": missing, "results": results})
|
||||
}
|
||||
|
||||
// normalizeFindingIDs drops non-positive and duplicate ids, then caps the list.
|
||||
func normalizeFindingIDs(ids []int64, capN int) []int64 {
|
||||
seen := make(map[int64]bool, len(ids))
|
||||
out := make([]int64, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if id <= 0 || seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
out = append(out, id)
|
||||
if capN > 0 && len(out) == capN {
|
||||
break
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// bulkPatchFindingReportState sets the same report stage on a batch of findings
|
||||
// in one transaction. Same cap/dedupe/per-id result as bulk status, without
|
||||
// status-change notifications: report_state is a workflow stage, not a verdict.
|
||||
func (s *Server) bulkPatchFindingReportState(w http.ResponseWriter, r *http.Request) {
|
||||
var body struct {
|
||||
IDs []int64 `json:"ids"`
|
||||
ReportState string `json:"report_state"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
writeErr(w, 400, "bad json: "+err.Error())
|
||||
return
|
||||
}
|
||||
if !db.ValidFindingReportState(body.ReportState) {
|
||||
writeErr(w, 400, "bad report_state: "+body.ReportState)
|
||||
return
|
||||
}
|
||||
ids := normalizeFindingIDs(body.IDs, maxBulkFindingStatus)
|
||||
if len(ids) == 0 {
|
||||
writeErr(w, 400, "no finding ids")
|
||||
return
|
||||
}
|
||||
results, err := s.m.pg.SetFindingReportStates(r.Context(), ids, body.ReportState)
|
||||
if err != nil {
|
||||
writeErr(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
updated, missing := 0, 0
|
||||
for _, res := range results {
|
||||
if res.Changed {
|
||||
updated++
|
||||
}
|
||||
if !res.Found {
|
||||
missing++
|
||||
}
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"updated": updated, "missing": missing, "results": results})
|
||||
}
|
||||
|
||||
// deleteFinding removes a finding (findings row + originating exploration node).
|
||||
// id is the standalone findings-table id (DTO finding_id).
|
||||
func (s *Server) deleteFinding(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -37,7 +37,14 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { statusMeta, type Tone, toneClasses } from "@/lib/status";
|
||||
import type { ActiveFindingRetest, Finding, FindingStatus, Severity, VerificationStatus } from "@/lib/types";
|
||||
import type {
|
||||
ActiveFindingRetest,
|
||||
Finding,
|
||||
FindingReportState,
|
||||
FindingStatus,
|
||||
Severity,
|
||||
VerificationStatus,
|
||||
} from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const SEVERITIES: Severity[] = ["critical", "high", "medium", "low"];
|
||||
@@ -62,6 +69,37 @@ export const VERIFICATION_STATUSES: VerificationStatus[] = [
|
||||
"false_positive",
|
||||
];
|
||||
|
||||
export const FINDING_REPORT_STATES: FindingReportState[] = [
|
||||
"none",
|
||||
"submitted",
|
||||
"accepted",
|
||||
"rejected",
|
||||
"duplicate",
|
||||
];
|
||||
|
||||
export const REPORT_STATE_META: Record<FindingReportState, { label: string; tone: Tone }> = {
|
||||
none: { label: "Not submitted", tone: "slate" },
|
||||
submitted: { label: "Submitted", tone: "amber" },
|
||||
accepted: { label: "Accepted", tone: "green" },
|
||||
rejected: { label: "Rejected", tone: "red" },
|
||||
duplicate: { label: "Duplicate report", tone: "neutral" },
|
||||
};
|
||||
|
||||
export function ReportStateBadge({ state }: { state?: FindingReportState }) {
|
||||
const value = state ?? "none";
|
||||
const meta = REPORT_STATE_META[value] ?? REPORT_STATE_META.none;
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex w-fit items-center whitespace-nowrap rounded-md border px-2 py-0.5 font-medium text-xs",
|
||||
toneClasses[meta.tone],
|
||||
)}
|
||||
>
|
||||
{meta.label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// Verification outcome → label/tone, on the same tone tokens StatusBadge uses.
|
||||
export const VERIFICATION_META: Record<VerificationStatus, { label: string; tone: Tone }> = {
|
||||
verified: { label: "Verified", tone: "green" },
|
||||
@@ -125,7 +163,7 @@ export function fmtTime(ts: string) {
|
||||
});
|
||||
}
|
||||
|
||||
const COLUMN_COUNT = 9;
|
||||
const COLUMN_COUNT = 10;
|
||||
|
||||
interface FindingsTableProps {
|
||||
items: Finding[];
|
||||
@@ -141,6 +179,7 @@ interface FindingsTableProps {
|
||||
saving: boolean;
|
||||
onSave: (finding: Finding) => void;
|
||||
onStatusChange: (finding: Finding, next: FindingStatus) => void;
|
||||
onReportStateChange: (finding: Finding, next: FindingReportState) => void;
|
||||
onRetest: (finding: Finding) => void;
|
||||
activeRetests: Record<string, ActiveFindingRetest>;
|
||||
onDeepen: (finding: Finding) => void;
|
||||
@@ -164,6 +203,7 @@ export function FindingsTable({
|
||||
saving,
|
||||
onSave,
|
||||
onStatusChange,
|
||||
onReportStateChange,
|
||||
onRetest,
|
||||
activeRetests,
|
||||
onDeepen,
|
||||
@@ -181,7 +221,7 @@ export function FindingsTable({
|
||||
|
||||
return (
|
||||
/* Fixed column widths keep expanded content from stretching the table; narrow screens scroll horizontally inside the table only. */
|
||||
<Table className="min-w-[60rem] table-fixed">
|
||||
<Table className="min-w-[68rem] table-fixed">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-8">
|
||||
@@ -196,6 +236,7 @@ export function FindingsTable({
|
||||
<TableHead>Vulnerability</TableHead>
|
||||
<TableHead className="w-44">Asset</TableHead>
|
||||
<TableHead className="w-28">Status</TableHead>
|
||||
<TableHead className="w-36">Report</TableHead>
|
||||
<TableHead className="w-32">Task</TableHead>
|
||||
<TableHead className="w-24">Time</TableHead>
|
||||
<TableHead className="w-48">Actions</TableHead>
|
||||
@@ -296,6 +337,27 @@ export function FindingsTable({
|
||||
<StatusBadge domain="finding" value={f.status} dot />
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell onClick={(e) => e.stopPropagation()}>
|
||||
{f.finding_id ? (
|
||||
<Select
|
||||
value={f.report_state ?? "none"}
|
||||
onValueChange={(v) => onReportStateChange(f, v as FindingReportState)}
|
||||
>
|
||||
<SelectTrigger size="sm" className="h-7 w-full border-none px-1 shadow-none focus-visible:ring-0">
|
||||
<ReportStateBadge state={f.report_state} />
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" align="end">
|
||||
{FINDING_REPORT_STATES.map((st) => (
|
||||
<SelectItem key={st} value={st}>
|
||||
{REPORT_STATE_META[st].label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
) : (
|
||||
<ReportStateBadge state={f.report_state} />
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{f.task_id ? (
|
||||
<Link
|
||||
|
||||
@@ -23,9 +23,14 @@ import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { api } from "@/lib/api";
|
||||
import { statusMeta } from "@/lib/status";
|
||||
import type { Finding, FindingStatus, Severity } from "@/lib/types";
|
||||
import type { Finding, FindingReportState, FindingStatus, Severity } from "@/lib/types";
|
||||
|
||||
import { VerificationBadge } from "../_components/findings-table";
|
||||
import {
|
||||
FINDING_REPORT_STATES,
|
||||
REPORT_STATE_META,
|
||||
ReportStateBadge,
|
||||
VerificationBadge,
|
||||
} from "../_components/findings-table";
|
||||
import { FindingLineageView } from "./lineage";
|
||||
|
||||
const SEVERITIES: Severity[] = ["critical", "high", "medium", "low"];
|
||||
@@ -112,6 +117,23 @@ function FindingDetailInner() {
|
||||
[finding, id],
|
||||
);
|
||||
|
||||
const changeReportState = React.useCallback(
|
||||
async (next: FindingReportState) => {
|
||||
if (!finding || finding.inherited || next === (finding.report_state ?? "none")) return;
|
||||
const prev = finding.report_state ?? "none";
|
||||
setFinding({ ...finding, report_state: next });
|
||||
try {
|
||||
const updated = await api.setFindingReportState(id, next);
|
||||
setFinding(updated);
|
||||
toast.success(`Report stage changed to "${REPORT_STATE_META[next].label}"`);
|
||||
} catch (e) {
|
||||
setFinding((cur) => (cur ? { ...cur, report_state: prev } : cur));
|
||||
toast.error("Update failed: " + (e as Error).message);
|
||||
}
|
||||
},
|
||||
[finding, id],
|
||||
);
|
||||
|
||||
if (!finding) {
|
||||
return (
|
||||
<div className="flex flex-1 flex-col items-center justify-center gap-3 p-10 text-center">
|
||||
@@ -148,6 +170,7 @@ function FindingDetailInner() {
|
||||
<Separator orientation="vertical" className="mx-1 h-4" />
|
||||
<StatusBadge domain="severity" value={finding.severity} dot />
|
||||
<StatusBadge domain="finding" value={finding.status} dot />
|
||||
<ReportStateBadge state={finding.report_state} />
|
||||
<VerificationBadge finding={finding} />
|
||||
{finding.inherited && finding.source_task_id && (
|
||||
<Badge variant="outline">Source task #{finding.source_task_id} · read-only</Badge>
|
||||
@@ -294,6 +317,30 @@ function FindingDetailInner() {
|
||||
)}
|
||||
</FieldRow>
|
||||
|
||||
<FieldRow label="Report stage">
|
||||
{finding.inherited ? (
|
||||
<ReportStateBadge state={finding.report_state} />
|
||||
) : (
|
||||
<Select
|
||||
value={finding.report_state ?? "none"}
|
||||
onValueChange={(v) => changeReportState(v as FindingReportState)}
|
||||
>
|
||||
<SelectTrigger size="sm" className="h-7 w-auto border-none px-1 shadow-none focus-visible:ring-0">
|
||||
<ReportStateBadge state={finding.report_state} />
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" align="end">
|
||||
<SelectGroup>
|
||||
{FINDING_REPORT_STATES.map((st) => (
|
||||
<SelectItem key={st} value={st}>
|
||||
{REPORT_STATE_META[st].label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</FieldRow>
|
||||
|
||||
{/* Verification: automated outcome; the note explains any state other than verified */}
|
||||
{finding.verification_status && (
|
||||
<FieldRow label="Verification">
|
||||
|
||||
@@ -8,8 +8,10 @@ import {
|
||||
ArrowUpRightIcon,
|
||||
BugIcon,
|
||||
ChevronRightIcon,
|
||||
CircleCheckIcon,
|
||||
ClockIcon,
|
||||
DownloadIcon,
|
||||
FileUpIcon,
|
||||
InfoIcon,
|
||||
SearchIcon,
|
||||
ShieldAlertIcon,
|
||||
@@ -46,6 +48,7 @@ import type {
|
||||
Finding,
|
||||
FindingAssetNode,
|
||||
FindingGroup,
|
||||
FindingReportState,
|
||||
FindingStats,
|
||||
FindingStatus,
|
||||
Severity,
|
||||
@@ -55,6 +58,7 @@ import { cn } from "@/lib/utils";
|
||||
|
||||
import { AssetTree, assetPathOf } from "./_components/asset-tree";
|
||||
import {
|
||||
FINDING_REPORT_STATES,
|
||||
FINDING_STATUSES,
|
||||
type FindingEdit,
|
||||
type FindingReport,
|
||||
@@ -62,6 +66,7 @@ import {
|
||||
findingRowKey,
|
||||
fmtTime,
|
||||
isSameFinding,
|
||||
REPORT_STATE_META,
|
||||
SEVERITIES,
|
||||
UNASSIGNED_TASK,
|
||||
VERIFICATION_META,
|
||||
@@ -124,6 +129,8 @@ function findingGroupKey(group: FindingGroup) {
|
||||
const EMPTY_STATS: FindingStats = {
|
||||
total: 0,
|
||||
pending: 0,
|
||||
submitted: 0,
|
||||
accepted: 0,
|
||||
critical: 0,
|
||||
high: 0,
|
||||
medium: 0,
|
||||
@@ -136,6 +143,7 @@ export default function FindingsPage() {
|
||||
const [view, setView] = React.useState<FindingView>("flat");
|
||||
const [severity, setSeverity] = React.useState<"all" | Severity>("all");
|
||||
const [status, setStatus] = React.useState<"all" | FindingStatus>("all");
|
||||
const [reportState, setReportState] = React.useState<"all" | FindingReportState>("all");
|
||||
const [verificationStatus, setVerificationStatus] = React.useState<"all" | VerificationStatus>("all");
|
||||
const [vulnclass, setVulnclass] = React.useState<string>("all");
|
||||
const [task, setTask] = React.useState<string>("all");
|
||||
@@ -167,7 +175,16 @@ export default function FindingsPage() {
|
||||
const retestRefreshVersion = React.useRef(0);
|
||||
const [deepenDescription, setDeepenDescription] = React.useState("");
|
||||
const [deepening, setDeepening] = React.useState(false);
|
||||
const filterFingerprint = JSON.stringify([severity, status, verificationStatus, vulnclass, task, sort, query]);
|
||||
const filterFingerprint = JSON.stringify([
|
||||
severity,
|
||||
status,
|
||||
reportState,
|
||||
verificationStatus,
|
||||
vulnclass,
|
||||
task,
|
||||
sort,
|
||||
query,
|
||||
]);
|
||||
const activeFilterFingerprint = React.useRef(filterFingerprint);
|
||||
activeFilterFingerprint.current = filterFingerprint;
|
||||
|
||||
@@ -205,6 +222,7 @@ export default function FindingsPage() {
|
||||
view?: unknown;
|
||||
severity?: unknown;
|
||||
status?: unknown;
|
||||
reportState?: unknown;
|
||||
verificationStatus?: unknown;
|
||||
vulnclass?: unknown;
|
||||
task?: unknown;
|
||||
@@ -217,6 +235,9 @@ export default function FindingsPage() {
|
||||
if (parsed.status === "all" || FINDING_STATUSES.includes(parsed.status as FindingStatus)) {
|
||||
setStatus(parsed.status as "all" | FindingStatus);
|
||||
}
|
||||
if (parsed.reportState === "all" || FINDING_REPORT_STATES.includes(parsed.reportState as FindingReportState)) {
|
||||
setReportState(parsed.reportState as "all" | FindingReportState);
|
||||
}
|
||||
if (
|
||||
parsed.verificationStatus === "all" ||
|
||||
VERIFICATION_STATUSES.includes(parsed.verificationStatus as VerificationStatus)
|
||||
@@ -237,9 +258,9 @@ export default function FindingsPage() {
|
||||
if (!preferencesHydrated) return;
|
||||
setLocalStorageValue(
|
||||
FINDING_LIST_PREFERENCE_KEY,
|
||||
JSON.stringify({ view, severity, status, verificationStatus, vulnclass, task, sort }),
|
||||
JSON.stringify({ view, severity, status, reportState, verificationStatus, vulnclass, task, sort }),
|
||||
);
|
||||
}, [preferencesHydrated, severity, sort, status, task, verificationStatus, view, vulnclass]);
|
||||
}, [preferencesHydrated, reportState, severity, sort, status, task, verificationStatus, view, vulnclass]);
|
||||
|
||||
React.useEffect(() => {
|
||||
const timer = window.setTimeout(() => setQuery(search.trim()), 300);
|
||||
@@ -299,7 +320,7 @@ export default function FindingsPage() {
|
||||
await api.exportFindings({
|
||||
format: exportFormat,
|
||||
scope: exportScope,
|
||||
filters: { severity, status, verificationStatus, vulnclass, task, query, sort },
|
||||
filters: { severity, status, reportState, verificationStatus, vulnclass, task, query, sort },
|
||||
ids: [...selectedIds],
|
||||
});
|
||||
setExportOpen(false);
|
||||
@@ -339,6 +360,7 @@ export default function FindingsPage() {
|
||||
pageSize: flatPageSize,
|
||||
severity,
|
||||
status,
|
||||
reportState,
|
||||
verificationStatus,
|
||||
vulnclass,
|
||||
task,
|
||||
@@ -360,6 +382,7 @@ export default function FindingsPage() {
|
||||
flatPageSize,
|
||||
severity,
|
||||
status,
|
||||
reportState,
|
||||
verificationStatus,
|
||||
vulnclass,
|
||||
task,
|
||||
@@ -375,7 +398,16 @@ export default function FindingsPage() {
|
||||
const request = ++assetTreeRequest.current;
|
||||
setAssetTree((current) => ({ ...current, loading: true }));
|
||||
try {
|
||||
const result = await api.findingAssetTree({ severity, status, verificationStatus, vulnclass, task, query, sort });
|
||||
const result = await api.findingAssetTree({
|
||||
severity,
|
||||
status,
|
||||
reportState,
|
||||
verificationStatus,
|
||||
vulnclass,
|
||||
task,
|
||||
query,
|
||||
sort,
|
||||
});
|
||||
if (request !== assetTreeRequest.current || activeFilterFingerprint.current !== requestFilter) return;
|
||||
setAssetTree({
|
||||
nodes: result.nodes ?? [],
|
||||
@@ -390,7 +422,7 @@ export default function FindingsPage() {
|
||||
setAssetTree((current) => ({ ...current, loading: false }));
|
||||
toast.error(`Failed to load the asset tree: ${(e as Error).message}`);
|
||||
}
|
||||
}, [filterFingerprint, severity, status, verificationStatus, vulnclass, task, query, sort]);
|
||||
}, [filterFingerprint, reportState, severity, status, verificationStatus, vulnclass, task, query, sort]);
|
||||
|
||||
const refreshGroups = React.useCallback(async () => {
|
||||
const requestFilter = filterFingerprint;
|
||||
@@ -402,6 +434,7 @@ export default function FindingsPage() {
|
||||
pageSize,
|
||||
severity,
|
||||
status,
|
||||
reportState,
|
||||
verificationStatus,
|
||||
vulnclass,
|
||||
task,
|
||||
@@ -415,7 +448,7 @@ export default function FindingsPage() {
|
||||
} catch {
|
||||
// Polling keeps the last successful snapshot visible.
|
||||
}
|
||||
}, [filterFingerprint, page, pageSize, severity, status, verificationStatus, vulnclass, task, query, sort]);
|
||||
}, [filterFingerprint, page, pageSize, reportState, severity, status, verificationStatus, vulnclass, task, query, sort]);
|
||||
|
||||
const loadGroup = React.useCallback(
|
||||
async (key: string, groupPage: number, groupPageSize: number) => {
|
||||
@@ -440,6 +473,7 @@ export default function FindingsPage() {
|
||||
pageSize: groupPageSize,
|
||||
severity,
|
||||
status,
|
||||
reportState,
|
||||
verificationStatus,
|
||||
vulnclass,
|
||||
task: key,
|
||||
@@ -475,7 +509,7 @@ export default function FindingsPage() {
|
||||
}));
|
||||
}
|
||||
},
|
||||
[filterFingerprint, severity, status, verificationStatus, vulnclass, query, sort],
|
||||
[filterFingerprint, reportState, severity, status, verificationStatus, vulnclass, query, sort],
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -657,6 +691,34 @@ export default function FindingsPage() {
|
||||
[refreshAfterMutation, setFindings, status],
|
||||
);
|
||||
|
||||
const updateReportState = React.useCallback(
|
||||
async (f: Finding, next: FindingReportState) => {
|
||||
if (!f.finding_id || next === (f.report_state ?? "none")) return;
|
||||
const prev = f.report_state ?? "none";
|
||||
setFindings((cur) => cur.map((x) => (isSameFinding(x, f) ? { ...x, report_state: next } : x)));
|
||||
try {
|
||||
await api.setFindingReportState(f.finding_id, next);
|
||||
toast.success(`Report stage set to "${REPORT_STATE_META[next].label}"`);
|
||||
api
|
||||
.findingStats()
|
||||
.then(setStats)
|
||||
.catch(() => {
|
||||
// The row update remains valid even if the aggregate refresh fails.
|
||||
});
|
||||
if (reportState !== "all" && next !== reportState) {
|
||||
setFindings((cur) => cur.filter((x) => !isSameFinding(x, f)));
|
||||
setTotal((t) => Math.max(0, t - 1));
|
||||
setFlat((cur) => ({ ...cur, total: Math.max(0, cur.total - 1) }));
|
||||
}
|
||||
refreshAfterMutation(f);
|
||||
} catch (e) {
|
||||
setFindings((cur) => cur.map((x) => (isSameFinding(x, f) ? { ...x, report_state: prev } : x)));
|
||||
toast.error(`Update failed: ${(e as Error).message}`);
|
||||
}
|
||||
},
|
||||
[refreshAfterMutation, reportState, setFindings],
|
||||
);
|
||||
|
||||
// applyBulkStatus sets the same triage status on every selected finding, then
|
||||
// reloads the current view so rows hidden by the status filter disappear.
|
||||
const applyBulkStatus = React.useCallback(
|
||||
@@ -687,6 +749,36 @@ export default function FindingsPage() {
|
||||
[bulkBusy, loadAssetTree, loadFlat, selectedIds, view],
|
||||
);
|
||||
|
||||
const applyBulkReportState = React.useCallback(
|
||||
async (next: FindingReportState) => {
|
||||
if (selectedIds.size === 0 || bulkBusy) return;
|
||||
setBulkBusy(true);
|
||||
try {
|
||||
const r = await api.bulkSetFindingReportState([...selectedIds], next);
|
||||
setSelectedIds(new Set());
|
||||
const label = REPORT_STATE_META[next].label;
|
||||
toast.success(
|
||||
r.updated === 1
|
||||
? `Set report stage of 1 finding to "${label}"`
|
||||
: `Set report stage of ${r.updated} findings to "${label}"`,
|
||||
);
|
||||
void loadFlat();
|
||||
if (view === "asset") void loadAssetTree();
|
||||
api
|
||||
.findingStats()
|
||||
.then(setStats)
|
||||
.catch(() => {
|
||||
// The list reload remains valid even if the aggregate refresh fails.
|
||||
});
|
||||
} catch (e) {
|
||||
toast.error(`Bulk update failed: ${(e as Error).message}`);
|
||||
} finally {
|
||||
setBulkBusy(false);
|
||||
}
|
||||
},
|
||||
[bulkBusy, loadAssetTree, loadFlat, selectedIds, view],
|
||||
);
|
||||
|
||||
// The inline expanded detailed-report cache is keyed by the globally stable row key. report is long-form
|
||||
// Markdown the list query doesn't include, so it is fetched once by finding_id on expand; done with empty text = no report yet.
|
||||
const [reports, setReports] = React.useState<Record<string, FindingReport>>({});
|
||||
@@ -812,6 +904,8 @@ export default function FindingsPage() {
|
||||
const statCards = [
|
||||
{ label: "Total findings", value: stats.total, icon: BugIcon },
|
||||
{ label: "Pending", value: stats.pending, tone: "text-amber-500", icon: ClockIcon },
|
||||
{ label: "Submitted", value: stats.submitted, tone: "text-amber-500", icon: FileUpIcon },
|
||||
{ label: "Accepted", value: stats.accepted, tone: "text-emerald-500", icon: CircleCheckIcon },
|
||||
{ label: "Critical", value: stats.critical, tone: "text-rose-600", icon: ShieldAlertIcon },
|
||||
{ label: "High", value: stats.high, tone: "text-red-500", icon: TriangleAlertIcon },
|
||||
{ label: "Medium", value: stats.medium, tone: "text-amber-500", icon: TriangleAlertIcon },
|
||||
@@ -838,6 +932,7 @@ export default function FindingsPage() {
|
||||
saving,
|
||||
onSave: saveEdit,
|
||||
onStatusChange: updateStatus,
|
||||
onReportStateChange: updateReportState,
|
||||
onRetest: setRetestFinding,
|
||||
activeRetests,
|
||||
onDeepen: openDeepen,
|
||||
@@ -888,7 +983,7 @@ export default function FindingsPage() {
|
||||
</Tabs>
|
||||
</div>
|
||||
<div className="flex flex-1 flex-col gap-4 md:gap-6">
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-6">
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-4 lg:grid-cols-8">
|
||||
{statCards.map((stat) => {
|
||||
const StatIcon = stat.icon;
|
||||
return (
|
||||
@@ -956,6 +1051,20 @@ export default function FindingsPage() {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select value={reportState} onValueChange={(v) => setReportState(v as "all" | FindingReportState)}>
|
||||
<SelectTrigger size="sm" className="w-40">
|
||||
<SelectValue placeholder="Report stage" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All report stages</SelectItem>
|
||||
{FINDING_REPORT_STATES.map((st) => (
|
||||
<SelectItem key={st} value={st}>
|
||||
{REPORT_STATE_META[st].label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Select
|
||||
value={verificationStatus}
|
||||
onValueChange={(v) => setVerificationStatus(v as "all" | VerificationStatus)}
|
||||
@@ -1046,6 +1155,24 @@ export default function FindingsPage() {
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Select
|
||||
value=""
|
||||
onValueChange={(v) => {
|
||||
if (v) void applyBulkReportState(v as FindingReportState);
|
||||
}}
|
||||
disabled={bulkBusy}
|
||||
>
|
||||
<SelectTrigger size="sm" className="w-44" aria-label="Set the report stage of the selected findings">
|
||||
<SelectValue placeholder={bulkBusy ? "Updating…" : "Set report stage"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{FINDING_REPORT_STATES.map((st) => (
|
||||
<SelectItem key={st} value={st}>
|
||||
{REPORT_STATE_META[st].label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
<Button size="sm" variant="outline" onClick={openExport}>
|
||||
|
||||
+10
-1
@@ -43,6 +43,7 @@ import type {
|
||||
FindingGroupsPage,
|
||||
FindingQuery,
|
||||
FindingRetest,
|
||||
FindingReportState,
|
||||
FindingStats,
|
||||
FindingStatus,
|
||||
FindingsPage,
|
||||
@@ -241,6 +242,7 @@ function findingFilterParams(q: Omit<FindingQuery, "page" | "pageSize">): URLSea
|
||||
const p = new URLSearchParams();
|
||||
if (q.severity && q.severity !== "all") p.set("severity", q.severity);
|
||||
if (q.status && q.status !== "all") p.set("status", q.status);
|
||||
if (q.reportState && q.reportState !== "all") p.set("report_state", q.reportState);
|
||||
if (q.verificationStatus && q.verificationStatus !== "all") p.set("verification_status", q.verificationStatus);
|
||||
if (q.vulnclass && q.vulnclass !== "all") p.set("vulnclass", q.vulnclass);
|
||||
if (q.task && q.task !== "all") p.set("task_id", q.task);
|
||||
@@ -703,6 +705,8 @@ export const api = {
|
||||
// Vulnerability lineage: the subgraph (nodes + edges) from the vulnerability node back to the task's initial node.
|
||||
findingLineage: (id: string) => get<{ nodes: TaskNode[]; edges: Edge[] }>(`/exploration/findings/${id}/lineage`),
|
||||
setFindingStatus: (id: string, status: FindingStatus) => patch<Finding>(`/exploration/findings/${id}`, { status }),
|
||||
setFindingReportState: (id: string, report_state: FindingReportState) =>
|
||||
patch<Finding>(`/exploration/findings/${id}`, { report_state }),
|
||||
// Bulk triage: one transaction server-side, with a per-id result. Unknown ids
|
||||
// come back as found=false instead of failing the whole batch.
|
||||
bulkSetFindingStatus: (ids: string[], status: FindingStatus) =>
|
||||
@@ -710,11 +714,16 @@ export const api = {
|
||||
"/exploration/findings/bulk-status",
|
||||
{ ids: ids.map(Number), status },
|
||||
),
|
||||
bulkSetFindingReportState: (ids: string[], report_state: FindingReportState) =>
|
||||
post<{ updated: number; missing: number; results: { id: number; found: boolean; changed: boolean }[] }>(
|
||||
"/exploration/findings/bulk-report-state",
|
||||
{ ids: ids.map(Number), report_state },
|
||||
),
|
||||
setFindingSeverity: (id: string, severity: Severity) => patch<Finding>(`/exploration/findings/${id}`, { severity }),
|
||||
// Save a vulnerability's name/class/severity in one call (inline edit in the findings list); only present fields are sent.
|
||||
updateFinding: (
|
||||
id: string,
|
||||
fields: { name?: string; vulnclass?: string; severity?: Severity; status?: FindingStatus },
|
||||
fields: { name?: string; vulnclass?: string; severity?: Severity; status?: FindingStatus; report_state?: FindingReportState },
|
||||
) => patch<Finding>(`/exploration/findings/${id}`, fields),
|
||||
// Delete a vulnerability: removes the findings record + the source exploration node (gone from the findings list, the task findings tab, and the exploration graph together).
|
||||
deleteFinding: (id: string) => del<{ deleted: boolean; id: number }>(`/exploration/findings/${id}`),
|
||||
|
||||
@@ -471,6 +471,8 @@ function mockFilterFindings(q: URLSearchParams): (typeof mockFindings)[number][]
|
||||
const taskID = q.get("task_id");
|
||||
if (severity) list = list.filter((finding) => finding.severity === severity);
|
||||
if (status) list = list.filter((finding) => finding.status === status);
|
||||
const reportState = q.get("report_state");
|
||||
if (reportState) list = list.filter((finding) => (finding.report_state ?? "none") === reportState);
|
||||
if (vulnclass) list = list.filter((finding) => finding.vulnclass === vulnclass);
|
||||
if (taskID === "__unassigned__") list = list.filter((finding) => !finding.task_id);
|
||||
else if (taskID) list = list.filter((finding) => finding.task_id === taskID);
|
||||
@@ -1866,6 +1868,8 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
return {
|
||||
total: mockFindings.length,
|
||||
pending: mockFindings.filter((f) => f.status === "pending").length,
|
||||
submitted: mockFindings.filter((f) => (f.report_state ?? "none") === "submitted").length,
|
||||
accepted: mockFindings.filter((f) => f.report_state === "accepted").length,
|
||||
critical: mockFindings.filter((f) => f.severity === "critical").length,
|
||||
high: mockFindings.filter((f) => f.severity === "high").length,
|
||||
medium: mockFindings.filter((f) => f.severity === "medium").length,
|
||||
@@ -1874,6 +1878,28 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
tasks,
|
||||
};
|
||||
}
|
||||
if (path === "/exploration/findings/bulk-report-state" && m === "POST") {
|
||||
const ids = Array.isArray(b.ids) ? b.ids : [];
|
||||
const state = typeof b.report_state === "string" ? b.report_state : "";
|
||||
let updated = 0;
|
||||
let missing = 0;
|
||||
const results = ids.map((id) => {
|
||||
const key = String(id);
|
||||
const f = mockFindings.find((item) => item.id === key);
|
||||
if (!f) {
|
||||
missing++;
|
||||
return { id, found: false, changed: false };
|
||||
}
|
||||
const from = f.report_state ?? "none";
|
||||
const changed = from !== state;
|
||||
if (changed) {
|
||||
f.report_state = state as typeof f.report_state;
|
||||
updated++;
|
||||
}
|
||||
return { id, found: true, changed, from };
|
||||
});
|
||||
return { updated, missing, results };
|
||||
}
|
||||
if (path === "/exploration/findings/asset-tree") {
|
||||
const list = mockApplyAssetScope(mockFilterFindings(q), null);
|
||||
return { nodes: mockBuildAssetTree(list), finding_total: list.length, truncated: false };
|
||||
@@ -2081,6 +2107,7 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
if (!f) return {};
|
||||
if (m === "PATCH") {
|
||||
if (typeof b.status === "string") f.status = b.status as typeof f.status;
|
||||
if (typeof b.report_state === "string") f.report_state = b.report_state as typeof f.report_state;
|
||||
if (typeof b.severity === "string") f.severity = b.severity as typeof f.severity;
|
||||
if (typeof b.name === "string") f.name = b.name;
|
||||
if (typeof b.vulnclass === "string") f.vulnclass = b.vulnclass;
|
||||
|
||||
@@ -486,6 +486,9 @@ export type FindingStatus =
|
||||
// human triage status above. "blocked" is produced by no path yet but is displayed when present.
|
||||
export type VerificationStatus = "verified" | "unverified" | "blocked" | "not_assessed" | "false_positive";
|
||||
|
||||
// Report stage after triage: a finding can be confirmed and submitted at the same time.
|
||||
export type FindingReportState = "none" | "submitted" | "accepted" | "rejected" | "duplicate";
|
||||
|
||||
// FindingAsset is an asset bound to a vulnerability (label pre-rendered by the backend).
|
||||
export interface FindingAsset {
|
||||
id: string;
|
||||
@@ -509,6 +512,7 @@ export interface Finding {
|
||||
name?: string; // vulnerability name; display falls back to vulnclass when empty
|
||||
severity: Severity;
|
||||
status: FindingStatus;
|
||||
report_state?: FindingReportState; // workflow stage after triage; default none
|
||||
summary: string;
|
||||
evidence: string;
|
||||
report?: string; // detailed report (Markdown); returned only by the detail endpoint, empty in lists
|
||||
@@ -562,6 +566,8 @@ export interface FindingDeepenResponse {
|
||||
export interface FindingStats {
|
||||
total: number;
|
||||
pending: number;
|
||||
submitted: number;
|
||||
accepted: number;
|
||||
critical: number;
|
||||
high: number;
|
||||
medium: number;
|
||||
@@ -585,6 +591,7 @@ export interface FindingQuery {
|
||||
pageSize: number;
|
||||
severity?: "all" | Severity;
|
||||
status?: "all" | FindingStatus;
|
||||
reportState?: "all" | FindingReportState;
|
||||
verificationStatus?: "all" | VerificationStatus;
|
||||
vulnclass?: string;
|
||||
task?: string; // task id; "all"/empty = no task filter
|
||||
|
||||
Reference in New Issue
Block a user