diff --git a/internal/database/vulnerability_workspace_test.go b/internal/database/vulnerability_workspace_test.go index 00307214..8d5ac6ad 100644 --- a/internal/database/vulnerability_workspace_test.go +++ b/internal/database/vulnerability_workspace_test.go @@ -39,12 +39,12 @@ func TestVulnerabilityWorkspaceTargetsAndLegacyUpgrade(t *testing.T) { func TestVulnerabilityDomainGroupsPreferNamesAndRepairStoredTargets(t *testing.T) { db := newRBACTestDB(t) - raw := "https://vpn.example.com/login (真实 IP 190.104.230.105,Citrix Gateway 26.6.1.20,Keycloak 4.4.0.final,Ivanti Connect Secure 22.x,getFunction.php)" + raw := "https://vpn.example.com/login (真实 IP 192.0.2.25,Citrix Gateway 26.6.1.20,Keycloak 4.4.0.final,Ivanti Connect Secure 22.x,getFunction.php)" v, err := db.CreateVulnerability(&Vulnerability{Title: "domain with infrastructure notes", Severity: "high", Target: raw}) if err != nil { t.Fatal(err) } - if len(v.Targets) != 2 || v.Targets[0].Host != "vpn.example.com" || !v.Targets[0].GroupHost || v.Targets[1].Host != "190.104.230.105" || v.Targets[1].GroupHost { + if len(v.Targets) != 2 || v.Targets[0].Host != "vpn.example.com" || !v.Targets[0].GroupHost || v.Targets[1].Host != "192.0.2.25" || v.Targets[1].GroupHost { t.Fatalf("parsed targets: %+v", v.Targets) } if _, err := db.Exec(`UPDATE vulnerabilities SET targets_json='[{"host":"22.x"}]',targets_version=1 WHERE id=?`, v.ID); err != nil { diff --git a/web/static/js/vulnerability.js b/web/static/js/vulnerability.js index 94bd9653..f853cb74 100644 --- a/web/static/js/vulnerability.js +++ b/web/static/js/vulnerability.js @@ -1420,7 +1420,7 @@ function renderVulnerabilities(vulnerabilities, renderOptions) { ? vulnerabilities[0].id : null; const expandedIds = exactMatch ? [exactMatch] : opts.expandedIds; - listContainer.innerHTML = vulnerabilities.map(renderVulnerabilityCard).join(''); + listContainer.innerHTML = renderVulnerabilityTable(vulnerabilities); initVulnerabilityStatusPickers(listContainer); initVulnerabilityProjectBindSelects(listContainer); if (typeof window.applyTranslations === 'function') { @@ -1613,7 +1613,18 @@ function renderVulnerabilityBrowserTable(expandedIds) { ).join('') + `${escapeHtml(vulnT('vulnerabilityPage.groupPending', { count: pending }))}`; document.getElementById('vulnerability-host-export').disabled = items.length === 0; const container = document.getElementById('vulnerability-host-table'); - container.innerHTML = items.length ? `
+ container.innerHTML = renderVulnerabilityTable(items); + initVulnerabilityStatusPickers(container); + initVulnerabilityProjectBindSelects(container); + if (typeof rbacAfterDynamicRender === 'function') rbacAfterDynamicRender(container); + const exact = items.find(vuln => vulnerabilityFilters.id === vuln.id); + if (exact?.summary_only && typeof openVulnerabilityInspector === 'function') openVulnerabilityInspector(exact.id); + else restoreExpandedVulnerabilityDetails(exact ? [exact.id] : expandedIds); + updateVulnerabilityListSummary(); +} + +function renderVulnerabilityTable(items) { + return items.length ? `
@@ -1627,13 +1638,6 @@ function renderVulnerabilityBrowserTable(expandedIds) { ${items.map(renderVulnerabilityTableItem).join('')}
` : `
${escapeHtml(vulnT('vulnerabilityPage.noRecords'))}
`; - initVulnerabilityStatusPickers(container); - initVulnerabilityProjectBindSelects(container); - if (typeof rbacAfterDynamicRender === 'function') rbacAfterDynamicRender(container); - const exact = items.find(vuln => vulnerabilityFilters.id === vuln.id); - if (exact?.summary_only && typeof openVulnerabilityInspector === 'function') openVulnerabilityInspector(exact.id); - else restoreExpandedVulnerabilityDetails(exact ? [exact.id] : expandedIds); - updateVulnerabilityListSummary(); } function renderVulnerabilityTableItem(vuln) { @@ -1676,66 +1680,6 @@ function renderVulnerabilityTableItem(vuln) { `; } -function renderVulnerabilityCard(vuln) { - const severityClass = `severity-${vuln.severity}`; - const severityText = vulnSeverityLabel(vuln.severity); - const createdDate = new Date(vuln.created_at).toLocaleString(vulnDateLocale()); - const projectLabel = vuln.project_id - ? escapeHtml(typeof getProjectName === 'function' ? getProjectName(vuln.project_id) : vuln.project_id) - : escapeHtml(vulnT('vulnerabilityPage.projectUnbound')); - const projectBadge = vuln.project_id - ? `${escapeHtml(vulnT('vulnerabilityPage.detailProject'))}: ${projectLabel}` - : `${escapeHtml(vulnT('vulnerabilityPage.projectUnbound'))}`; - const dlTitle = escapeHtml(vulnT('vulnerabilityDownload.download')); - const editTitle = escapeHtml(vulnT('common.edit')); - const deleteTitle = escapeHtml(vulnT('common.delete')); - const vulnIdJs = escapeJsStringAttr(vuln.id); - - return ` -
-
-
-
- - - -

${escapeHtml(vuln.title)}

- ${typeof vulnerabilitySelectionInput === 'function' ? vulnerabilitySelectionInput(vuln) : ''} -
-
- ${severityText} - ${buildVulnerabilityStatusPicker(vuln)} - ${projectBadge} - ${createdDate} -
-
-
- - - - -
-
- ${vuln.summary_only ? '' : renderVulnerabilityDetailsContent(vuln)} -
- `; -} - function renderVulnerabilityDetailsContent(vuln) { return `