fix(server): count only the task's assets in the task report

GET /api/report renders one task's report, but its "Assets:" summary line
was built from QueryByType over the whole asset library, so it reported
every task's and every company's assets as this task's. It also loaded up
to 100000 full rows per type only to count them.

Use CountsByTypeForTask, the per-task count the assets tab already uses.
This commit is contained in:
Chaitanya Deshpande
2026-11-26 17:09:05 +05:30
parent 3cb06383fd
commit 1fceeb3479
2 changed files with 76 additions and 7 deletions
+1 -7
View File
@@ -4583,14 +4583,8 @@ func (s *Server) getReport(w http.ResponseWriter, r *http.Request) {
return
}
findings, _ := t.Store.ListByKind(db.KindFinding, 1000) // pure vulnerabilities (facts are a separate KindFact and never enter the report)
counts := map[string]int{}
for _, ty := range []string{"root_domain", "ip", "subdomain", "app", "service", "endpoint"} {
ns, _ := s.m.Assets().QueryByType(ty, 100000, 0)
if len(ns) > 0 {
counts[ty] = len(ns)
}
}
taskID, _ := strconv.ParseInt(t.ID, 10, 64)
counts, _ := s.m.Assets().CountsByTypeForTask(taskID)
var ledger *db.CoverageLedger
if t.CoverageEnabled {
ledger, _ = s.m.Assets().CoverageLedger(taskID)