Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update backend_structured/routes.py
Browse files- backend_structured/routes.py +26 -3
backend_structured/routes.py
CHANGED
|
@@ -1154,13 +1154,36 @@ def get_global_stats(current_user):
|
|
| 1154 |
'created_at': p.created_at.isoformat() + 'Z' if p.created_at else None
|
| 1155 |
})
|
| 1156 |
|
| 1157 |
-
# Get global vulnerability trends
|
| 1158 |
trends_query = db.session.query(
|
| 1159 |
Vulnerability.title,
|
| 1160 |
db.func.count(Vulnerability.id).label('count')
|
| 1161 |
-
).
|
|
|
|
| 1162 |
|
| 1163 |
-
trends_data = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1164 |
|
| 1165 |
# Get recent audit logs enriched with user emails and target names (limit 10 for dashboard preview)
|
| 1166 |
audit_logs_query = AuditLog.query.order_by(AuditLog.created_at.desc()).limit(10).all()
|
|
|
|
| 1154 |
'created_at': p.created_at.isoformat() + 'Z' if p.created_at else None
|
| 1155 |
})
|
| 1156 |
|
| 1157 |
+
# Get global vulnerability trends enriched with details
|
| 1158 |
trends_query = db.session.query(
|
| 1159 |
Vulnerability.title,
|
| 1160 |
db.func.count(Vulnerability.id).label('count')
|
| 1161 |
+
).filter(Vulnerability.is_false_positive.isnot(True))\
|
| 1162 |
+
.group_by(Vulnerability.title).order_by(db.func.count(Vulnerability.id).desc()).limit(15).all()
|
| 1163 |
|
| 1164 |
+
trends_data = []
|
| 1165 |
+
for title, count in trends_query:
|
| 1166 |
+
sample = Vulnerability.query.filter_by(title=title).filter(Vulnerability.is_false_positive.isnot(True)).first()
|
| 1167 |
+
|
| 1168 |
+
affected_scans = db.session.query(Scan.target_url)\
|
| 1169 |
+
.join(Vulnerability, Vulnerability.scan_id == Scan.id)\
|
| 1170 |
+
.filter(Vulnerability.title == title)\
|
| 1171 |
+
.distinct().limit(5).all()
|
| 1172 |
+
affected_urls = [s[0] for s in affected_scans if s[0]]
|
| 1173 |
+
|
| 1174 |
+
trends_data.append({
|
| 1175 |
+
'title': title,
|
| 1176 |
+
'count': count,
|
| 1177 |
+
'severity': sample.severity if sample else 'Medium',
|
| 1178 |
+
'category': sample.category if sample else 'Security Audit',
|
| 1179 |
+
'description': sample.description if sample else f'Global vulnerability "{title}" identified across multiple scanned targets.',
|
| 1180 |
+
'remediation': sample.remediation if sample else 'Review server configuration files, apply security patches, and enforce strict HTTP security headers.',
|
| 1181 |
+
'cvss_score': sample.cvss_score if (sample and sample.cvss_score) else 5.0,
|
| 1182 |
+
'owasp_category': getattr(sample, 'owasp_category', None) or 'A05:2021 - Security Misconfiguration',
|
| 1183 |
+
'cwe_ids': getattr(sample, 'cwe_ids', None) or [],
|
| 1184 |
+
'evidence': getattr(sample, 'evidence', None) or '',
|
| 1185 |
+
'affected_targets': affected_urls
|
| 1186 |
+
})
|
| 1187 |
|
| 1188 |
# Get recent audit logs enriched with user emails and target names (limit 10 for dashboard preview)
|
| 1189 |
audit_logs_query = AuditLog.query.order_by(AuditLog.created_at.desc()).limit(10).all()
|