mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-12-01 15:43:33 +01:00
feat(vulnerabilities): show timestamps and support oldest-first ordering
This commit is contained in:
1 parent
1e4603f16b
commit
5b2f87d205
11 files changed
+71
-18
No files matched your search
@@ -374,6 +374,9 @@ func (db *DB) ListVulnerabilitiesByGroupForAccess(limit, offset int, filter Vuln
|
||||
case "severity":
|
||||
itemOrder = vulnerabilitySeverityRankExpr + ", created_at DESC, id"
|
||||
groupOrder = "group_severity, group_latest DESC, " + groupOrder
|
||||
case "oldest":
|
||||
itemOrder = "created_at ASC, id"
|
||||
groupOrder = "group_oldest ASC, " + groupOrder
|
||||
case "latest":
|
||||
groupOrder = "group_latest DESC, " + groupOrder
|
||||
}
|
||||
@@ -382,12 +385,12 @@ func (db *DB) ListVulnerabilitiesByGroupForAccess(limit, offset int, filter Vuln
|
||||
if groupQuery != "" {
|
||||
prefix = `WITH scoped AS (` + groupQuery + `),
|
||||
page_groups AS (
|
||||
SELECT group_key, MIN(group_is_ip) AS group_is_ip, MIN(severity_rank) AS group_severity, MAX(created_at) AS group_latest
|
||||
SELECT group_key, MIN(group_is_ip) AS group_is_ip, MIN(severity_rank) AS group_severity, MAX(created_at) AS group_latest, MIN(created_at) AS group_oldest
|
||||
FROM scoped GROUP BY group_key
|
||||
ORDER BY ` + groupOrder + ` LIMIT ? OFFSET ?
|
||||
),
|
||||
page_items AS (
|
||||
SELECT scoped.id, scoped.group_key, page_groups.group_is_ip, page_groups.group_severity, page_groups.group_latest
|
||||
SELECT scoped.id, scoped.group_key, page_groups.group_is_ip, page_groups.group_severity, page_groups.group_latest, page_groups.group_oldest
|
||||
FROM scoped JOIN page_groups USING (group_key)
|
||||
)`
|
||||
args = append(args, limit, offset)
|
||||
|
||||
@@ -190,8 +190,8 @@ func (h *VulnerabilityHandler) ListVulnerabilities(c *gin.Context) {
|
||||
access := vulnerabilityAccessFromContext(c)
|
||||
groupBy := c.Query("group_by")
|
||||
sortBy := c.Query("sort")
|
||||
if sortBy != "" && sortBy != "severity" && sortBy != "latest" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "sort must be severity or latest"})
|
||||
if sortBy != "" && sortBy != "severity" && sortBy != "latest" && sortBy != "oldest" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "sort must be severity, latest or oldest"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +124,10 @@ func TestListVulnerabilitiesGroupedViews(t *testing.T) {
|
||||
{"group_by=task&sort=severity&page=2", []string{"domain-new", "filtered", "ipv6"}},
|
||||
{"group_by=host&sort=latest", []string{"filtered", "domain-new", "domain-old", "unknown"}},
|
||||
{"group_by=task&sort=latest", []string{"filtered", "ipv6", "domain-new", "unknown"}},
|
||||
{"group_by=none&sort=oldest", []string{"domain-old", "domain-new"}},
|
||||
{"group_by=none&sort=oldest&page=2", []string{"subdomain", "ipv6"}},
|
||||
{"group_by=host&sort=oldest", []string{"domain-old", "domain-new", "filtered", "domain-old"}},
|
||||
{"group_by=task&sort=oldest", []string{"domain-old", "subdomain", "domain-new", "ipv6", "filtered"}},
|
||||
{"group_by=none&sort=severity", []string{"domain-old", "unknown"}},
|
||||
{"group_by=host&sort=severity&severity=high", []string{"unknown", "subdomain"}},
|
||||
{"group_by=host&sort=latest&q=missing", []string{}},
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
|
||||
.vulnerability-record-row {
|
||||
display: grid;
|
||||
grid-template-columns: 18px 52px minmax(0, 1fr) auto;
|
||||
grid-template-columns: 18px 52px minmax(220px, 1fr) auto max-content;
|
||||
overflow-x: auto;
|
||||
align-items: center;
|
||||
column-gap: 12px;
|
||||
min-height: 72px;
|
||||
@@ -124,7 +125,7 @@
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.vulnerability-record-row {
|
||||
grid-template-columns: 18px 46px minmax(0, 1fr);
|
||||
grid-template-columns: 18px 46px minmax(200px, 1fr) auto max-content;
|
||||
gap: 8px;
|
||||
padding: 12px;
|
||||
}
|
||||
@@ -133,7 +134,24 @@
|
||||
min-height: 0 !important;
|
||||
}
|
||||
.vulnerability-record-actions {
|
||||
grid-column: 2 / -1;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
.vulnerability-record-time {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
white-space: nowrap;
|
||||
font-size: 12px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.vulnerability-record-time-label { font-size: 11px; }
|
||||
|
||||
/* Keep the status menu inside the scrollable row without clipping its options. */
|
||||
.vulnerability-record-row .vuln-status-picker-menu {
|
||||
position: static;
|
||||
margin-top: 6px;
|
||||
}
|
||||
@@ -2820,7 +2820,8 @@
|
||||
"sortLabel": "الترتيب",
|
||||
"sortDefault": "الترتيب الافتراضي",
|
||||
"sortSeverity": "الأعلى خطورة أولاً",
|
||||
"sortLatest": "الأحدث أولاً",
|
||||
"sortLatest": "الإنشاء: الأحدث أولاً",
|
||||
"sortOldest": "الإنشاء: الأقدم أولاً",
|
||||
"expandPage": "توسيع الصفحة",
|
||||
"collapsePage": "طي الصفحة",
|
||||
"hostPagination": "عرض {{start}}–{{end}} من أصل {{total}} مجموعة حسب المضيف",
|
||||
|
||||
@@ -2962,7 +2962,8 @@
|
||||
"sortLabel": "Sort",
|
||||
"sortDefault": "Default order",
|
||||
"sortSeverity": "Severity first",
|
||||
"sortLatest": "Newest findings",
|
||||
"sortLatest": "Created: newest first",
|
||||
"sortOldest": "Created: oldest first",
|
||||
"expandPage": "Expand page",
|
||||
"collapsePage": "Collapse page",
|
||||
"hostPagination": "Showing {{start}}–{{end}} of {{total}} host groups",
|
||||
|
||||
@@ -2975,7 +2975,8 @@
|
||||
"sortLabel": "Сортировка",
|
||||
"sortDefault": "По умолчанию",
|
||||
"sortSeverity": "По критичности",
|
||||
"sortLatest": "Сначала новые",
|
||||
"sortLatest": "Создание: сначала новые",
|
||||
"sortOldest": "Создание: сначала старые",
|
||||
"expandPage": "Развернуть страницу",
|
||||
"collapsePage": "Свернуть страницу",
|
||||
"hostPagination": "Показано {{start}}–{{end}} из {{total}} групп по хостам",
|
||||
|
||||
@@ -2950,7 +2950,8 @@
|
||||
"sortLabel": "排序",
|
||||
"sortDefault": "默认顺序",
|
||||
"sortSeverity": "高危优先",
|
||||
"sortLatest": "最新发现",
|
||||
"sortLatest": "创建时间:最新优先",
|
||||
"sortOldest": "创建时间:最早优先",
|
||||
"expandPage": "展开本页",
|
||||
"collapsePage": "收起本页",
|
||||
"hostPagination": "显示 {{start}}–{{end}} / 共 {{total}} 个域名组",
|
||||
|
||||
@@ -146,7 +146,8 @@ async function openVulnerabilityInspector(id) {
|
||||
<span class="severity-badge severity-${escapeAttr(v.severity)}">${escapeHtml(vulnSeverityLabel(v.severity))}</span>
|
||||
${buildVulnerabilityStatusPicker(v)}
|
||||
<span>${escapeHtml(v.type || '')}</span>
|
||||
<span>${escapeHtml(new Date(v.created_at).toLocaleString(vulnDateLocale()))}</span>
|
||||
<span>${escapeHtml(vulnT('vulnerabilityMd.labelCreated'))}: ${renderVulnerabilityTimestamp(v.created_at)}</span>
|
||||
<span>${escapeHtml(vulnT('vulnerabilityMd.labelUpdated'))}: ${renderVulnerabilityTimestamp(v.updated_at)}</span>
|
||||
</div>
|
||||
<div class="vulnerability-inspector-actions">
|
||||
<button class="btn-primary" data-require-permission="vulnerability:write" onclick="openVulnerabilityRetest(${jsID})" ${v.conversation_id ? '' : 'disabled'}>${escapeHtml(vulnT('vulnerabilityRetest.button'))}</button>
|
||||
|
||||
@@ -239,7 +239,7 @@ let vulnerabilityView = savedVulnerabilityView === 'case' ? 'none'
|
||||
let vulnerabilityListRequest = 0;
|
||||
let vulnerabilityStatsRequest = 0;
|
||||
const savedVulnerabilitySort = localStorage.getItem('vulnerabilityListSort');
|
||||
let vulnerabilitySort = ['severity', 'latest'].includes(savedVulnerabilitySort) ? savedVulnerabilitySort : '';
|
||||
let vulnerabilitySort = ['severity', 'latest', 'oldest'].includes(savedVulnerabilitySort) ? savedVulnerabilitySort : '';
|
||||
let vulnerabilityHostQuery = '';
|
||||
let vulnerabilityTaskQuery = '';
|
||||
let vulnerabilityBrowserSelection = '';
|
||||
@@ -1402,7 +1402,7 @@ function renderVulnerabilities(vulnerabilities, renderOptions) {
|
||||
}
|
||||
|
||||
function changeVulnerabilitySort(value) {
|
||||
if (!['', 'severity', 'latest'].includes(value)) return;
|
||||
if (!['', 'severity', 'latest', 'oldest'].includes(value)) return;
|
||||
vulnerabilitySort = value;
|
||||
localStorage.setItem('vulnerabilityListSort', value);
|
||||
loadVulnerabilities(1);
|
||||
@@ -1597,6 +1597,24 @@ function renderVulnerabilityList(items) {
|
||||
return `<ul class="vulnerability-record-list">${items.map(renderVulnerabilityListItem).join('')}</ul>`;
|
||||
}
|
||||
|
||||
// Use the browser's local timezone and preserve seconds for chronological comparison.
|
||||
function formatVulnerabilityTimestamp(value) {
|
||||
if (!value) return '—';
|
||||
const date = new Date(value);
|
||||
if (!Number.isFinite(date.getTime())) return '—';
|
||||
return date.toLocaleString(vulnDateLocale(), {
|
||||
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false
|
||||
});
|
||||
}
|
||||
|
||||
function renderVulnerabilityTimestamp(value) {
|
||||
const label = formatVulnerabilityTimestamp(value);
|
||||
if (label === '—') return label;
|
||||
const iso = new Date(value).toISOString();
|
||||
return `<time datetime="${escapeAttr(iso)}" title="${escapeAttr(iso)}">${escapeHtml(label)}</time>`;
|
||||
}
|
||||
|
||||
function renderVulnerabilityListItem(vuln) {
|
||||
const id = escapeAttr(vuln.id);
|
||||
const jsID = escapeJsStringAttr(vuln.id);
|
||||
@@ -1615,6 +1633,10 @@ function renderVulnerabilityListItem(vuln) {
|
||||
${buildVulnerabilityStatusPicker(vuln)}
|
||||
<button type="button" class="vulnerability-record-view" aria-haspopup="dialog" onclick="openVulnerabilityInspector(${jsID})">${escapeHtml(vulnT('vulnerabilityPage.viewFinding'))}</button>
|
||||
</div>
|
||||
<span class="vulnerability-record-time">
|
||||
<span class="vulnerability-record-time-label">${escapeHtml(vulnT('vulnerabilityMd.labelCreated'))}</span>
|
||||
${renderVulnerabilityTimestamp(vuln.created_at)}
|
||||
</span>
|
||||
</li>`;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<!-- 移动端样式层:全部规则限定在 767.98px 以下,桌面端零影响 -->
|
||||
<link rel="stylesheet" href="/static/css/mobile.css?v=20261015-project-table-3">
|
||||
<link rel="stylesheet" href="/static/css/vulnerability-workspace.css?v=20261113-aligned-overview">
|
||||
<link rel="stylesheet" href="/static/css/vulnerability-list.css?v=20261113-compact-rows">
|
||||
<link rel="stylesheet" href="/static/css/vulnerability-list.css?v=20261115-timestamps">
|
||||
<script src="/static/js/router.js?v=20261011-token-settings"></script>
|
||||
</head>
|
||||
<body>
|
||||
@@ -2864,7 +2864,8 @@
|
||||
<select id="vulnerability-sort" onchange="changeVulnerabilitySort(this.value)">
|
||||
<option value="" data-i18n="vulnerabilityPage.sortDefault">默认顺序</option>
|
||||
<option value="severity" data-i18n="vulnerabilityPage.sortSeverity">高危优先</option>
|
||||
<option value="latest" data-i18n="vulnerabilityPage.sortLatest">最新发现</option>
|
||||
<option value="latest" data-i18n="vulnerabilityPage.sortLatest">创建时间:最新优先</option>
|
||||
<option value="oldest" data-i18n="vulnerabilityPage.sortOldest">创建时间:最早优先</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
@@ -7106,8 +7107,8 @@
|
||||
<script src="/static/js/skills.js?v=20261027-pagination-custom-select"></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-aligned-overview"></script>
|
||||
<script src="/static/js/vulnerability-workspace.js?v=20261113-compact-rows"></script>
|
||||
<script src="/static/js/vulnerability.js?v=20261115-timestamps"></script>
|
||||
<script src="/static/js/vulnerability-workspace.js?v=20261115-timestamps"></script>
|
||||
<script src="/static/js/vulnerability-download.js?v=20261030-2"></script>
|
||||
<script src="/static/js/webshell.js?v=20261011-token-usage"></script>
|
||||
<script src="/static/js/chat-files.js?v=20261027-pagination-custom-select"></script>
|
||||
|
||||
Reference in new issue
Block a user