Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update backend/utils/pdf_generator.py
Browse files
backend/utils/pdf_generator.py
CHANGED
|
@@ -989,15 +989,23 @@ def generate_scan_pdf(scan, vulnerabilities):
|
|
| 989 |
for u_idx, u_vuln in enumerate(unconfirmed_findings, start=1):
|
| 990 |
u_title = getattr(u_vuln, 'title', f"Unconfirmed Finding #{u_idx}")
|
| 991 |
u_cvss = str(getattr(u_vuln, 'cvss_score', '0.0'))
|
| 992 |
-
u_cat = getattr(u_vuln, 'category', 'General')
|
| 993 |
-
u_sev = getattr(u_vuln, 'severity', 'Low')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 994 |
u_desc = getattr(u_vuln, 'description', '')
|
| 995 |
-
u_vec = getattr(u_vuln, 'cvss_vector', 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N')
|
| 996 |
|
| 997 |
elements.append(Paragraph(f"<b>A.{u_idx} {html.escape(u_title)} [Requires Verification]</b>", styles['Heading3']))
|
| 998 |
u_data = [
|
| 999 |
["Status", Paragraph("<font color='#EA580C'>Requires Verification</font>", normal), "CVSS Score", u_cvss],
|
| 1000 |
-
["Category", u_cat, "Severity", Paragraph(f"<font color='
|
| 1001 |
["CVSS Vector", u_vec, "", ""]
|
| 1002 |
]
|
| 1003 |
u_table = Table(u_data, colWidths=[80, 150, 80, 150])
|
|
@@ -1009,9 +1017,46 @@ def generate_scan_pdf(scan, vulnerabilities):
|
|
| 1009 |
]))
|
| 1010 |
elements.append(u_table)
|
| 1011 |
elements.append(Spacer(1, 8))
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1015 |
|
| 1016 |
# Legal Disclaimer & Confidentiality Notice
|
| 1017 |
elements.append(PageBreak())
|
|
|
|
| 989 |
for u_idx, u_vuln in enumerate(unconfirmed_findings, start=1):
|
| 990 |
u_title = getattr(u_vuln, 'title', f"Unconfirmed Finding #{u_idx}")
|
| 991 |
u_cvss = str(getattr(u_vuln, 'cvss_score', '0.0'))
|
| 992 |
+
u_cat = html.escape(str(getattr(u_vuln, 'category', 'General')))
|
| 993 |
+
u_sev = str(getattr(u_vuln, 'severity', 'Low')).capitalize()
|
| 994 |
+
|
| 995 |
+
u_sev_lower = u_sev.lower()
|
| 996 |
+
if 'critical' in u_sev_lower: u_sev_hex = '#DC2626'
|
| 997 |
+
elif 'high' in u_sev_lower: u_sev_hex = '#EA580C'
|
| 998 |
+
elif 'medium' in u_sev_lower: u_sev_hex = '#D97706'
|
| 999 |
+
elif 'low' in u_sev_lower: u_sev_hex = '#99CC33'
|
| 1000 |
+
else: u_sev_hex = '#2563EB'
|
| 1001 |
+
|
| 1002 |
u_desc = getattr(u_vuln, 'description', '')
|
| 1003 |
+
u_vec = html.escape(str(getattr(u_vuln, 'cvss_vector', 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N')))
|
| 1004 |
|
| 1005 |
elements.append(Paragraph(f"<b>A.{u_idx} {html.escape(u_title)} [Requires Verification]</b>", styles['Heading3']))
|
| 1006 |
u_data = [
|
| 1007 |
["Status", Paragraph("<font color='#EA580C'>Requires Verification</font>", normal), "CVSS Score", u_cvss],
|
| 1008 |
+
["Category", u_cat, "Severity", Paragraph(f"<font color='{u_sev_hex}'>{u_sev}</font>", normal)],
|
| 1009 |
["CVSS Vector", u_vec, "", ""]
|
| 1010 |
]
|
| 1011 |
u_table = Table(u_data, colWidths=[80, 150, 80, 150])
|
|
|
|
| 1017 |
]))
|
| 1018 |
elements.append(u_table)
|
| 1019 |
elements.append(Spacer(1, 8))
|
| 1020 |
+
|
| 1021 |
+
if u_desc:
|
| 1022 |
+
u_desc_html = markdown_to_reportlab_html(u_desc)
|
| 1023 |
+
elements.append(Paragraph(f"<b>Description:</b><br/>{u_desc_html}", normal))
|
| 1024 |
+
elements.append(Spacer(1, 10))
|
| 1025 |
+
|
| 1026 |
+
u_proof_text = get_proof_of_detection(u_vuln, domain)
|
| 1027 |
+
if u_proof_text:
|
| 1028 |
+
elements.append(Paragraph("<b>Proof of Detection (Engine Payload Audit Log):</b>", styles['Normal']))
|
| 1029 |
+
elements.append(Spacer(1, 5))
|
| 1030 |
+
u_proof_lines = u_proof_text.split('\n')
|
| 1031 |
+
u_proof_html = []
|
| 1032 |
+
for line in u_proof_lines:
|
| 1033 |
+
escaped = html.escape(line).replace(" ", " ")
|
| 1034 |
+
if escaped.startswith("#"):
|
| 1035 |
+
u_proof_html.append(f"<font color='#94A3B8'>{escaped}</font>")
|
| 1036 |
+
elif "[Detection]" in escaped or "[System]" in escaped or "[Evidence]" in escaped:
|
| 1037 |
+
u_proof_html.append(f"<font color='#93C5FD'>{escaped}</font>")
|
| 1038 |
+
else:
|
| 1039 |
+
u_proof_html.append(f"<font color='#F8FAFC'>{escaped}</font>")
|
| 1040 |
+
|
| 1041 |
+
u_proof_str = "<br/>".join(u_proof_html)
|
| 1042 |
+
u_proof_table = Table([[Paragraph(f"<font face='Courier' size='8'>{u_proof_str}</font>", normal)]], colWidths=[460])
|
| 1043 |
+
u_proof_table.setStyle(TableStyle([
|
| 1044 |
+
('BACKGROUND', (0,0), (-1,-1), colors.HexColor("#0B0F19")),
|
| 1045 |
+
('TOPPADDING', (0,0), (-1,-1), 12),
|
| 1046 |
+
('BOTTOMPADDING', (0,0), (-1,-1), 12),
|
| 1047 |
+
('LEFTPADDING', (0,0), (-1,-1), 12),
|
| 1048 |
+
('RIGHTPADDING', (0,0), (-1,-1), 12),
|
| 1049 |
+
('CORNER_RADIUS', (0,0), (-1,-1), 4),
|
| 1050 |
+
]))
|
| 1051 |
+
elements.append(u_proof_table)
|
| 1052 |
+
elements.append(Spacer(1, 12))
|
| 1053 |
+
|
| 1054 |
+
u_rem = getattr(u_vuln, 'remediation', None)
|
| 1055 |
+
if u_rem:
|
| 1056 |
+
elements.append(Paragraph("<b>Remediation:</b>", styles['Normal']))
|
| 1057 |
+
u_rem_html = markdown_to_reportlab_html(u_rem)
|
| 1058 |
+
elements.append(Paragraph(u_rem_html, normal))
|
| 1059 |
+
elements.append(Spacer(1, 15))
|
| 1060 |
|
| 1061 |
# Legal Disclaimer & Confidentiality Notice
|
| 1062 |
elements.append(PageBreak())
|