refactor(vulnerabilities): use the shared list for raw findings

This commit is contained in:
Sycun 2026-11-13 17:00:00 +08:00
parent 5538829d4a
commit 9c5dce5656
3 changed files with 16 additions and 72 deletions

View File

@ -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 {

View File

@ -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('') + `<span class="vulnerability-group-pending">${escapeHtml(vulnT('vulnerabilityPage.groupPending', { count: pending }))}</span>`;
document.getElementById('vulnerability-host-export').disabled = items.length === 0;
const container = document.getElementById('vulnerability-host-table');
container.innerHTML = items.length ? `<div class="vulnerability-table-scroll">
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 ? `<div class="vulnerability-table-scroll">
<table class="vulnerability-host-table">
<colgroup>
<col class="vulnerability-col-select"><col class="vulnerability-col-severity"><col>
@ -1627,13 +1638,6 @@ function renderVulnerabilityBrowserTable(expandedIds) {
</tr></thead>
${items.map(renderVulnerabilityTableItem).join('')}
</table></div>` : `<div class="empty-state">${escapeHtml(vulnT('vulnerabilityPage.noRecords'))}</div>`;
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) {
</tbody>`;
}
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
? `<span class="vulnerability-project-badge" title="${escapeAttr(vuln.project_id)}">${escapeHtml(vulnT('vulnerabilityPage.detailProject'))}: ${projectLabel}</span>`
: `<span class="vulnerability-project-badge vulnerability-project-badge--unbound">${escapeHtml(vulnT('vulnerabilityPage.projectUnbound'))}</span>`;
const dlTitle = escapeHtml(vulnT('vulnerabilityDownload.download'));
const editTitle = escapeHtml(vulnT('common.edit'));
const deleteTitle = escapeHtml(vulnT('common.delete'));
const vulnIdJs = escapeJsStringAttr(vuln.id);
return `
<div class="vulnerability-card ${severityClass}" id="vulnerability-card-${escapeAttr(vuln.id)}" data-vuln-id="${escapeAttr(vuln.id)}">
<div class="vulnerability-header" onclick="${vuln.summary_only ? 'openVulnerabilityInspector' : 'toggleVulnerabilityDetails'}(${vulnIdJs})" style="cursor: pointer;">
<div class="vulnerability-title-section">
<div style="display: flex; align-items: center; gap: 8px;">
<svg class="vulnerability-expand-icon" id="expand-icon-${escapeAttr(vuln.id)}" width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" style="transition: transform 0.2s ease; flex-shrink: 0;">
<path d="M9 18l6-6-6-6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<h3 class="vulnerability-title">${escapeHtml(vuln.title)}</h3>
${typeof vulnerabilitySelectionInput === 'function' ? vulnerabilitySelectionInput(vuln) : ''}
</div>
<div class="vulnerability-meta">
<span class="severity-badge ${severityClass}">${severityText}</span>
${buildVulnerabilityStatusPicker(vuln)}
${projectBadge}
<span class="vulnerability-date">${createdDate}</span>
</div>
</div>
<div class="vulnerability-actions" onclick="event.stopPropagation();">
<button type="button" class="btn-ghost" data-require-permission="vulnerability:write" onclick="openVulnerabilityRetest(${vulnIdJs})" ${vuln.conversation_id ? '' : 'disabled'}>${escapeHtml(vulnT('vulnerabilityRetest.button'))}</button>
<button class="btn-ghost" type="button" onclick="openVulnerabilityDownload(${vulnIdJs}, event)" title="${dlTitle}" aria-label="${dlTitle}">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<polyline points="7 10 12 15 17 10" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<line x1="12" y1="15" x2="12" y2="3" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<button class="btn-ghost" onclick="editVulnerability(${vulnIdJs})" title="${editTitle}">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<button class="btn-ghost" data-require-permission="vulnerability:delete" onclick="deleteVulnerability(${vulnIdJs})" title="${deleteTitle}">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6h14z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
${vuln.summary_only ? '' : renderVulnerabilityDetailsContent(vuln)}
</div>
`;
}
function renderVulnerabilityDetailsContent(vuln) {
return `
<div class="vulnerability-content" id="content-${vuln.id}" style="display: none;">

View File

@ -7131,7 +7131,7 @@
<script src="/static/js/skills.js?v=20261103-personal-integration"></script>
<script src="/static/js/fact-graph.js"></script>
<script src="/static/js/projects.js?v=20260819-1-pagination-20261027"></script>
<script src="/static/js/vulnerability.js?v=20261113-tree-views"></script>
<script src="/static/js/vulnerability.js?v=20261113-unified-list"></script>
<script src="/static/js/vulnerability-workspace.js?v=20261113-drawer-dismiss"></script>
<script src="/static/js/vulnerability-download.js?v=20261030-2"></script>
<script src="/static/js/webshell.js?v=20261011-token-usage-tool-title"></script>