Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update backend_structured/routes.py
Browse files- backend_structured/routes.py +26 -20
backend_structured/routes.py
CHANGED
|
@@ -1823,7 +1823,7 @@ def fetch_scan_logs(current_user, scan_id):
|
|
| 1823 |
def get_scans_history(current_user):
|
| 1824 |
try:
|
| 1825 |
|
| 1826 |
-
limit_val = request.args.get('limit',
|
| 1827 |
org_id_param = request.args.get('org_id')
|
| 1828 |
is_global = request.args.get('global') == 'true'
|
| 1829 |
|
|
@@ -1904,20 +1904,28 @@ def get_scan_details(current_user, scan_id):
|
|
| 1904 |
if not scan:
|
| 1905 |
return jsonify({"message": "Scan session not found!"}), 404
|
| 1906 |
|
| 1907 |
-
|
| 1908 |
-
|
| 1909 |
-
|
| 1910 |
-
|
| 1911 |
-
|
| 1912 |
-
|
| 1913 |
-
|
| 1914 |
-
|
| 1915 |
-
|
| 1916 |
-
|
| 1917 |
-
|
| 1918 |
-
|
| 1919 |
-
|
| 1920 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1921 |
effective_score = scan.security_score
|
| 1922 |
if scan.status == "completed":
|
| 1923 |
effective_score = calculate_security_score_from_counts(counts)
|
|
@@ -1931,10 +1939,8 @@ def get_scan_details(current_user, scan_id):
|
|
| 1931 |
"scan_type": scan.scan_type,
|
| 1932 |
"status": scan.status,
|
| 1933 |
"security_score": effective_score,
|
| 1934 |
-
"started_at": scan.started_at
|
| 1935 |
-
"completed_at": (
|
| 1936 |
-
scan.completed_at.isoformat() + "Z"
|
| 1937 |
-
) if scan.completed_at else None,
|
| 1938 |
"vulnerabilities_count": {
|
| 1939 |
"critical": crit,
|
| 1940 |
"high": high,
|
|
@@ -1991,7 +1997,7 @@ def get_scan_vulnerabilities(current_user, scan_id):
|
|
| 1991 |
"cvss_score": v.cvss_score,
|
| 1992 |
"description": v.description,
|
| 1993 |
"remediation": v.remediation,
|
| 1994 |
-
"detected_at": v.detected_at
|
| 1995 |
"evidence": v.evidence or "",
|
| 1996 |
"payload": v.payload or "",
|
| 1997 |
"request_details": v.request_details or "",
|
|
|
|
| 1823 |
def get_scans_history(current_user):
|
| 1824 |
try:
|
| 1825 |
|
| 1826 |
+
limit_val = min(request.args.get('limit', 100, type=int), 200)
|
| 1827 |
org_id_param = request.args.get('org_id')
|
| 1828 |
is_global = request.args.get('global') == 'true'
|
| 1829 |
|
|
|
|
| 1904 |
if not scan:
|
| 1905 |
return jsonify({"message": "Scan session not found!"}), 404
|
| 1906 |
|
| 1907 |
+
counts = {"critical": 0, "high": 0, "medium": 0, "low": 0}
|
| 1908 |
+
vuln_counts = (
|
| 1909 |
+
db.session.query(
|
| 1910 |
+
Vulnerability.severity,
|
| 1911 |
+
func.count(Vulnerability.id)
|
| 1912 |
+
)
|
| 1913 |
+
.filter(
|
| 1914 |
+
Vulnerability.scan_id == scan.id,
|
| 1915 |
+
Vulnerability.is_false_positive.isnot(True)
|
| 1916 |
+
)
|
| 1917 |
+
.group_by(Vulnerability.severity)
|
| 1918 |
+
.all()
|
| 1919 |
+
)
|
| 1920 |
+
for severity, count in vuln_counts:
|
| 1921 |
+
if severity and severity.lower() in counts:
|
| 1922 |
+
counts[severity.lower()] = count
|
| 1923 |
+
|
| 1924 |
+
crit = counts["critical"]
|
| 1925 |
+
high = counts["high"]
|
| 1926 |
+
med = counts["medium"]
|
| 1927 |
+
low = counts["low"]
|
| 1928 |
+
|
| 1929 |
effective_score = scan.security_score
|
| 1930 |
if scan.status == "completed":
|
| 1931 |
effective_score = calculate_security_score_from_counts(counts)
|
|
|
|
| 1939 |
"scan_type": scan.scan_type,
|
| 1940 |
"status": scan.status,
|
| 1941 |
"security_score": effective_score,
|
| 1942 |
+
"started_at": format_iso_timestamp(scan.started_at),
|
| 1943 |
+
"completed_at": format_iso_timestamp(scan.completed_at),
|
|
|
|
|
|
|
| 1944 |
"vulnerabilities_count": {
|
| 1945 |
"critical": crit,
|
| 1946 |
"high": high,
|
|
|
|
| 1997 |
"cvss_score": v.cvss_score,
|
| 1998 |
"description": v.description,
|
| 1999 |
"remediation": v.remediation,
|
| 2000 |
+
"detected_at": format_iso_timestamp(v.detected_at),
|
| 2001 |
"evidence": v.evidence or "",
|
| 2002 |
"payload": v.payload or "",
|
| 2003 |
"request_details": v.request_details or "",
|