mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-22 17:11:51 +08:00
feat: expose traffic IDs and filter finding statistics
This commit is contained in:
1 parent
459a484237
commit
8ee94f2215
14 files changed
+333
-70
No files matched your search
@@ -630,30 +630,38 @@ export default function FindingsPage() {
|
||||
if (flatPage > lastPage) setFlatPage(lastPage);
|
||||
}, [flat.loaded, flat.total, flatPage, flatPageSize]);
|
||||
|
||||
// Whole-table aggregates (stat cards + vuln-class options) — independent of the
|
||||
// current page, so they stay exact.
|
||||
const statsQuery = React.useMemo(
|
||||
() => ({ severity, status, vulnclass, task, query, ...dateRange, assetScope: activeAssetScope ?? undefined }),
|
||||
[severity, status, vulnclass, task, query, dateRange, activeAssetScope],
|
||||
);
|
||||
const statsFingerprint = JSON.stringify(statsQuery);
|
||||
const activeStatsFingerprint = React.useRef(statsFingerprint);
|
||||
activeStatsFingerprint.current = statsFingerprint;
|
||||
const statsRequest = React.useRef(0);
|
||||
const refreshStats = React.useCallback(async () => {
|
||||
if (activeStatsFingerprint.current !== statsFingerprint) return;
|
||||
const request = ++statsRequest.current;
|
||||
try {
|
||||
const result = await api.findingStats(statsQuery);
|
||||
if (request !== statsRequest.current || activeStatsFingerprint.current !== statsFingerprint) return;
|
||||
setStats(result);
|
||||
setStatsLoaded(true);
|
||||
} catch {
|
||||
// Retain the previous snapshot during transient refresh failures.
|
||||
}
|
||||
}, [statsQuery, statsFingerprint]);
|
||||
|
||||
// Counts use the current filters and asset subtree, independently of pagination.
|
||||
React.useEffect(() => {
|
||||
let alive = true;
|
||||
const load = () => {
|
||||
api
|
||||
.findingStats()
|
||||
.then((s) => {
|
||||
if (alive) {
|
||||
setStats(s);
|
||||
setStatsLoaded(true);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Keep the previous aggregate snapshot until the next poll.
|
||||
});
|
||||
};
|
||||
load();
|
||||
const t = setInterval(load, 5000);
|
||||
if (!preferencesHydrated) return;
|
||||
void activeRetestFingerprint;
|
||||
void refreshStats();
|
||||
const t = setInterval(() => void refreshStats(), 5000);
|
||||
return () => {
|
||||
alive = false;
|
||||
statsRequest.current++;
|
||||
clearInterval(t);
|
||||
};
|
||||
}, []);
|
||||
}, [preferencesHydrated, refreshStats, activeRetestFingerprint]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!statsLoaded) return;
|
||||
@@ -677,12 +685,7 @@ export default function FindingsPage() {
|
||||
await api.setFindingStatus(f.finding_id, next);
|
||||
toast.success(`已标记为「${statusMeta("finding", next).label}」`);
|
||||
// refresh stat cards (pending count) and drop the row if it no longer matches the status filter
|
||||
api
|
||||
.findingStats()
|
||||
.then(setStats)
|
||||
.catch(() => {
|
||||
// The row update remains valid even if the aggregate refresh fails.
|
||||
});
|
||||
void refreshStats();
|
||||
if (status !== "all" && next !== status) {
|
||||
setFindings((cur) => cur.filter((x) => !isSameFinding(x, f)));
|
||||
setTotal((t) => Math.max(0, t - 1));
|
||||
@@ -694,7 +697,7 @@ export default function FindingsPage() {
|
||||
toast.error(`更新失败:${(e as Error).message}`);
|
||||
}
|
||||
},
|
||||
[refreshAfterMutation, setFindings, status],
|
||||
[refreshAfterMutation, refreshStats, setFindings, status],
|
||||
);
|
||||
|
||||
// 行内展开的详细报告缓存按全局稳定行键存。report 是大段 Markdown,列表查询不带它,
|
||||
@@ -747,12 +750,7 @@ export default function FindingsPage() {
|
||||
),
|
||||
);
|
||||
toast.success("已保存");
|
||||
api
|
||||
.findingStats()
|
||||
.then(setStats)
|
||||
.catch(() => {
|
||||
// The edit remains valid even if the aggregate refresh fails.
|
||||
});
|
||||
void refreshStats();
|
||||
refreshAfterMutation(f);
|
||||
} catch (e) {
|
||||
toast.error(`保存失败:${(e as Error).message}`);
|
||||
@@ -760,7 +758,7 @@ export default function FindingsPage() {
|
||||
setSaving(false);
|
||||
}
|
||||
},
|
||||
[edit, refreshAfterMutation, setFindings],
|
||||
[edit, refreshAfterMutation, refreshStats, setFindings],
|
||||
);
|
||||
|
||||
// deleteFinding 删除一个漏洞(需二次确认):删成功后从列表移除、收起行、刷新统计。
|
||||
@@ -780,18 +778,13 @@ export default function FindingsPage() {
|
||||
const rowKey = findingRowKey(f);
|
||||
setExpanded((cur) => (cur === rowKey ? null : cur));
|
||||
toast.success("已删除漏洞");
|
||||
api
|
||||
.findingStats()
|
||||
.then(setStats)
|
||||
.catch(() => {
|
||||
// The deletion remains valid even if the aggregate refresh fails.
|
||||
});
|
||||
void refreshStats();
|
||||
refreshAfterMutation(f, true);
|
||||
} catch (e) {
|
||||
toast.error(`删除失败:${(e as Error).message}`);
|
||||
}
|
||||
},
|
||||
[refreshAfterMutation, setFindings],
|
||||
[refreshAfterMutation, refreshStats, setFindings],
|
||||
);
|
||||
|
||||
const openDeepen = React.useCallback((f: Finding) => {
|
||||
@@ -822,10 +815,10 @@ export default function FindingsPage() {
|
||||
const statCards = [
|
||||
{ label: "独立漏洞", value: stats.distinct?.total ?? stats.total, icon: BugIcon },
|
||||
{ label: "上报记录", value: stats.total, tone: "text-amber-500", icon: ClockIcon },
|
||||
{ label: "严重", value: stats.distinct?.critical ?? stats.critical, tone: "text-rose-600", icon: ShieldAlertIcon },
|
||||
{ label: "高危", value: stats.distinct?.high ?? stats.high, tone: "text-red-500", icon: TriangleAlertIcon },
|
||||
{ label: "中危", value: stats.distinct?.medium ?? stats.medium, tone: "text-amber-500", icon: TriangleAlertIcon },
|
||||
{ label: "低危", value: stats.distinct?.low ?? stats.low, tone: "text-slate-500", icon: InfoIcon },
|
||||
{ label: "严重", value: stats.critical, tone: "text-rose-600", icon: ShieldAlertIcon },
|
||||
{ label: "高危", value: stats.high, tone: "text-red-500", icon: TriangleAlertIcon },
|
||||
{ label: "中危", value: stats.medium, tone: "text-amber-500", icon: TriangleAlertIcon },
|
||||
{ label: "低危", value: stats.low, tone: "text-slate-500", icon: InfoIcon },
|
||||
];
|
||||
|
||||
// 导出弹窗里「当前筛选」的条数:两个视图的筛选一致,只是统计口径来源不同。
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
ArrowUpNarrowWideIcon,
|
||||
ChevronLeftIcon,
|
||||
ChevronRightIcon,
|
||||
CopyIcon,
|
||||
EraserIcon,
|
||||
FilterXIcon,
|
||||
ListChecksIcon,
|
||||
@@ -81,6 +82,30 @@ function MethodBadge({ method }: { method: string }) {
|
||||
return <Badge className="shrink-0 font-mono">{method}</Badge>;
|
||||
}
|
||||
|
||||
function TrafficID({ id }: { id: string }) {
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-7 gap-1 px-1 font-mono text-xs"
|
||||
title="复制流量 ID,可用于搜索或交给报告 Agent"
|
||||
aria-label={`复制流量 ID ${id}`}
|
||||
onClick={async (event) => {
|
||||
event.stopPropagation();
|
||||
try {
|
||||
await navigator.clipboard.writeText(id);
|
||||
toast.success("已复制流量 ID");
|
||||
} catch {
|
||||
toast.error("复制失败,请手动选择流量 ID");
|
||||
}
|
||||
}}
|
||||
>
|
||||
{id}
|
||||
<CopyIcon className="size-3 shrink-0" />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
// Older captures may predate Host persistence because net/http keeps Host
|
||||
// outside Request.Header. Fill it for display while newly recorded traffic is
|
||||
// fixed at the recorder layer as well.
|
||||
@@ -247,7 +272,22 @@ export function TrafficHistory({ taskId }: { taskId?: string }) {
|
||||
alive = false;
|
||||
clearInterval(t);
|
||||
};
|
||||
}, [page, size, hostQ, method, queryQ, bodyQ, pathQ, statusFilter, respMinQ, respMaxQ, sort, reloadTick, taskId, taskScoped]);
|
||||
}, [
|
||||
page,
|
||||
size,
|
||||
hostQ,
|
||||
method,
|
||||
queryQ,
|
||||
bodyQ,
|
||||
pathQ,
|
||||
statusFilter,
|
||||
respMinQ,
|
||||
respMaxQ,
|
||||
sort,
|
||||
reloadTick,
|
||||
taskId,
|
||||
taskScoped,
|
||||
]);
|
||||
|
||||
// Delete traffic for the current host filter (substring) or the checked
|
||||
// hosts (exact batch), then refetch.
|
||||
@@ -537,7 +577,7 @@ export function TrafficHistory({ taskId }: { taskId?: string }) {
|
||||
<div className="relative max-w-sm flex-1">
|
||||
<SearchIcon className="absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="搜索全部(URL / 方法 / 类型 / 状态码…)"
|
||||
placeholder="搜索全部(ID / URL / 方法 / 类型 / 状态码…)"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
className="h-8 pl-8"
|
||||
@@ -699,6 +739,7 @@ export function TrafficHistory({ taskId }: { taskId?: string }) {
|
||||
}
|
||||
/>
|
||||
</TableHead>
|
||||
<TableHead className="w-44">流量 ID</TableHead>
|
||||
<SortableHead
|
||||
field="ts"
|
||||
label="时间"
|
||||
@@ -752,6 +793,9 @@ export function TrafficHistory({ taskId }: { taskId?: string }) {
|
||||
}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<TrafficID id={e.id} />
|
||||
</TableCell>
|
||||
<TableCell className="text-xs text-muted-foreground tabular-nums">{fmtTime(e.ts)}</TableCell>
|
||||
<TableCell className="font-mono text-xs">{e.host}</TableCell>
|
||||
<TableCell>
|
||||
@@ -771,7 +815,7 @@ export function TrafficHistory({ taskId }: { taskId?: string }) {
|
||||
))}
|
||||
{exchanges.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={8} className="py-12 text-center text-sm text-muted-foreground">
|
||||
<TableCell colSpan={9} className="py-12 text-center text-sm text-muted-foreground">
|
||||
{traffic === null ? "加载中…" : "没有匹配的流量。"}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -803,6 +847,10 @@ export function TrafficHistory({ taskId }: { taskId?: string }) {
|
||||
</div>
|
||||
<SheetTitle className="break-all font-mono">{selected.host}</SheetTitle>
|
||||
<SheetDescription className="break-all font-mono">{selected.url}</SheetDescription>
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
流量 ID:
|
||||
<TrafficID id={selected.id} />
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
|
||||
+2
-1
@@ -708,7 +708,8 @@ export const api = {
|
||||
{ case_id: id },
|
||||
),
|
||||
findingCaseReviewRuns: () => get<FindingCaseReviewRun[]>("/exploration/finding-case-review"),
|
||||
findingStats: () => get<FindingStats>("/exploration/findings/stats"),
|
||||
findingStats: (q: Omit<FindingQuery, "page" | "pageSize"> = {}) =>
|
||||
get<FindingStats>(`/exploration/findings/stats?${findingFilterParams(q).toString()}`),
|
||||
// exportFindings 触发发现页导出并下载文件。scope=selected 时传 ids(finding_id 列表);
|
||||
// scope=filtered 时传当前筛选(沿用 FindingQuery 的筛选字段);scope=all 忽略筛选。
|
||||
exportFindings: async (opts: {
|
||||
|
||||
@@ -132,3 +132,30 @@ test("group dates use the latest matching finding after filters", async () => {
|
||||
assert.equal(result.items[0].task_id, "10");
|
||||
assert.equal(result.items[0].last_found_at, fixtures[8].ts);
|
||||
});
|
||||
|
||||
test("finding statistics follow combined filters and retain global choices", async () => {
|
||||
const route = { path: "/exploration/findings/stats" };
|
||||
const all = await read(route);
|
||||
const filtered = await read(route, {
|
||||
task_id: "10",
|
||||
severity: "high",
|
||||
status: "pending",
|
||||
vulnclass: "Demo",
|
||||
q: "needle",
|
||||
from: "2026-01-04T00:00:00Z",
|
||||
to: "2026-01-04T23:59:59Z",
|
||||
page: "2",
|
||||
limit: "1",
|
||||
});
|
||||
assert.equal(filtered.total, 1);
|
||||
assert.equal(filtered.distinct.total, 1);
|
||||
assert.equal(filtered.high, 1);
|
||||
assert.equal(filtered.critical, 0);
|
||||
assert.deepEqual(filtered.tasks, all.tasks);
|
||||
assert.deepEqual(filtered.vulnclasses, all.vulnclasses);
|
||||
const empty = await read(route, { q: "no matching fixture" });
|
||||
assert.equal(empty.total, 0);
|
||||
assert.equal(empty.distinct.total, 0);
|
||||
assert.equal(empty.high + empty.medium + empty.low + empty.critical, 0);
|
||||
assert.deepEqual(empty.tasks, all.tasks);
|
||||
});
|
||||
@@ -2001,6 +2001,7 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
// ── exploration ──
|
||||
if (path === "/exploration/frontier") return D.frontier;
|
||||
if (path === "/exploration/findings/stats") {
|
||||
const list = mockApplyAssetScope(mockFilterFindings(q), q.get("asset_scope"));
|
||||
const vulnclasses = Array.from(new Set(mockFindings.map((f) => f.vulnclass))).sort();
|
||||
// 「按任务」下拉:有漏洞的任务 + 描述 + 条数(mock 任务 id 是字符串,直接当 id 用)。
|
||||
const taskMap = new Map<string, { name: string; description: string; count: number }>();
|
||||
@@ -2017,12 +2018,13 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
}
|
||||
const tasks = Array.from(taskMap, ([id, v]) => ({ id, name: v.name, description: v.description, count: v.count }));
|
||||
return {
|
||||
total: mockFindings.length,
|
||||
pending: mockFindings.filter((f) => f.status === "pending").length,
|
||||
critical: mockFindings.filter((f) => f.severity === "critical").length,
|
||||
high: mockFindings.filter((f) => f.severity === "high").length,
|
||||
medium: mockFindings.filter((f) => f.severity === "medium").length,
|
||||
low: mockFindings.filter((f) => f.severity === "low").length,
|
||||
total: list.length,
|
||||
pending: list.filter((f) => f.status === "pending").length,
|
||||
critical: list.filter((f) => f.severity === "critical").length,
|
||||
high: list.filter((f) => f.severity === "high").length,
|
||||
medium: list.filter((f) => f.severity === "medium").length,
|
||||
low: list.filter((f) => f.severity === "low").length,
|
||||
distinct: { total: list.length, reports: list.length },
|
||||
vulnclasses,
|
||||
tasks,
|
||||
};
|
||||
|
||||
@@ -579,7 +579,7 @@ export interface FindingDeepenResponse {
|
||||
queued: boolean;
|
||||
}
|
||||
|
||||
// FindingStats 是发现全表聚合(统计卡 + 漏洞类型下拉),服务端计算,不受分页影响。
|
||||
// FindingStats 的计数跟随列表筛选,不受分页影响;类型和任务选项保留全局范围。
|
||||
export interface FindingStats {
|
||||
distinct?: FindingDistinctStats;
|
||||
total: number;
|
||||
|
||||
Reference in new issue
Block a user