Get all findings for a specific scan. Args: scan_id: Scan ID to get findings for Returns: List of finding dicts
(self, scan_id: str)
| 2204 | json.dumps(tags) if tags else None, |
| 2205 | matched_at, template_id, |
| 2206 | raw_output[:10000] if raw_output else None, |
| 2207 | json.dumps(details) if details else None |
| 2208 | )) |
| 2209 | |
| 2210 | conn.commit() |
| 2211 | return True |
| 2212 | except Exception as e: |
| 2213 | logger.error(f"Failed to save finding {finding_id}: {e}") |
| 2214 | return False |
| 2215 | |
| 2216 | def get_scan_findings(self, scan_id: str) -> List[Dict[str, Any]]: |
| 2217 | """ |
| 2218 | Get all findings for a specific scan. |
| 2219 | |
| 2220 | Args: |
| 2221 | scan_id: Scan ID to get findings for |
| 2222 | |
| 2223 | Returns: |
| 2224 | List of finding dicts |
| 2225 | """ |
| 2226 | try: |
| 2227 | with self.get_connection() as conn: |
| 2228 | cursor = conn.cursor() |
| 2229 | cursor.execute(""" |
| 2230 | SELECT * FROM scan_findings |
| 2231 | WHERE scan_id = ? |
| 2232 | ORDER BY |
| 2233 | CASE severity |
| 2234 | WHEN 'critical' THEN 1 |
| 2235 | WHEN 'high' THEN 2 |
| 2236 | WHEN 'medium' THEN 3 |
| 2237 | WHEN 'low' THEN 4 |
| 2238 | ELSE 5 |
| 2239 | END, |
| 2240 | timestamp DESC |
| 2241 | """, (scan_id,)) |
| 2242 | |
| 2243 | results = [] |
| 2244 | for row in cursor.fetchall(): |
| 2245 | result = dict(row) |
| 2246 | # Parse JSON fields |
| 2247 | for field in ['cve_ids', 'cwe_ids', 'reference_urls', 'tags', 'details']: |
| 2248 | if result.get(field): |
| 2249 | try: |
| 2250 | result[field] = json.loads(result[field]) |
| 2251 | except json.JSONDecodeError: |