链路图展示该漏洞所属任务探索图里,从初始节点(任务根)追溯到本漏洞节点的
那条链路:漏洞节点 + 其全部祖先(沿边反向可达)+ 之间的关系边。
- db.ExplorationStore.FindingLineage(nodeID):递归 CTE 取祖先子图(节点+边),
下游(如 finding→proves→goal)与无关节点不纳入
- GET /api/exploration/findings/{id}/lineage:解析 finding 的 node_id/task_id →
返回 {nodes,edges};无节点/任务已删 → 空图
- 前端 api.findingLineage;详情页 Tab 改为「概览 / 链路图」
- lineage.tsx:按深度拓扑排序,自根到漏洞纵向展示节点卡片 + 入边关系标注,
漏洞节点高亮
- db 测试补 FindingLineage 断言(含祖先/排除下游 goal/排除无关意图)
go build / db / server 测试通过。
353 lines
12 KiB
TypeScript
353 lines
12 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import Link from "next/link";
|
|
import { useSearchParams } from "next/navigation";
|
|
import { toast } from "sonner";
|
|
import { ArrowLeftIcon, ArrowUpRightIcon, ShieldAlertIcon } from "lucide-react";
|
|
|
|
import { SidebarTrigger } from "@/components/ui/sidebar";
|
|
import { Separator } from "@/components/ui/separator";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
} from "@/components/ui/select";
|
|
import { StatusBadge } from "@/components/status-badge";
|
|
import { Markdown } from "@/components/markdown";
|
|
import { FindingLineageView } from "./lineage";
|
|
import { statusMeta } from "@/lib/status";
|
|
import { api } from "@/lib/api";
|
|
import type { Finding, FindingStatus, Severity } from "@/lib/types";
|
|
|
|
const SEVERITIES: Severity[] = ["critical", "high", "medium", "low"];
|
|
const FINDING_STATUSES: FindingStatus[] = [
|
|
"pending",
|
|
"in_progress",
|
|
"confirmed",
|
|
"resolved",
|
|
"false_positive",
|
|
"ignored",
|
|
"duplicate",
|
|
"risk_accepted",
|
|
];
|
|
|
|
function fmtTime(ts: string) {
|
|
return new Date(ts).toLocaleString("zh-CN");
|
|
}
|
|
|
|
// FieldRow is one label/value line in the right-hand status panel.
|
|
function FieldRow({
|
|
label,
|
|
children,
|
|
}: {
|
|
label: string;
|
|
children: React.ReactNode;
|
|
}) {
|
|
return (
|
|
<div className="flex items-start justify-between gap-3 py-2.5">
|
|
<span className="shrink-0 pt-0.5 text-xs text-muted-foreground">
|
|
{label}
|
|
</span>
|
|
<div className="flex min-w-0 flex-col items-end gap-1 text-right text-sm">
|
|
{children}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function FindingDetailInner() {
|
|
const searchParams = useSearchParams();
|
|
const id = searchParams.get("id") ?? "";
|
|
const [finding, setFinding] = React.useState<Finding | null>(null);
|
|
const [loaded, setLoaded] = React.useState(false);
|
|
const [tab, setTab] = React.useState("overview");
|
|
|
|
const load = React.useCallback(() => {
|
|
if (!id) {
|
|
setLoaded(true);
|
|
return;
|
|
}
|
|
api
|
|
.getFinding(id)
|
|
.then((f) => setFinding(f))
|
|
.catch(() => setFinding(null))
|
|
.finally(() => setLoaded(true));
|
|
}, [id]);
|
|
React.useEffect(() => {
|
|
load();
|
|
}, [load]);
|
|
|
|
const changeSeverity = React.useCallback(
|
|
async (next: Severity) => {
|
|
if (!finding || next === finding.severity) return;
|
|
const prev = finding.severity;
|
|
setFinding({ ...finding, severity: next });
|
|
try {
|
|
const updated = await api.setFindingSeverity(id, next);
|
|
setFinding(updated);
|
|
toast.success(`严重等级已改为「${statusMeta("severity", next).label}」`);
|
|
} catch (e) {
|
|
setFinding((cur) => (cur ? { ...cur, severity: prev } : cur));
|
|
toast.error("更新失败:" + (e as Error).message);
|
|
}
|
|
},
|
|
[finding, id],
|
|
);
|
|
|
|
const changeStatus = React.useCallback(
|
|
async (next: FindingStatus) => {
|
|
if (!finding || next === finding.status) return;
|
|
const prev = finding.status;
|
|
setFinding({ ...finding, status: next });
|
|
try {
|
|
const updated = await api.setFindingStatus(id, next);
|
|
setFinding(updated);
|
|
toast.success(`处理状态已改为「${statusMeta("finding", next).label}」`);
|
|
} catch (e) {
|
|
setFinding((cur) => (cur ? { ...cur, status: prev } : cur));
|
|
toast.error("更新失败:" + (e as Error).message);
|
|
}
|
|
},
|
|
[finding, id],
|
|
);
|
|
|
|
if (!finding) {
|
|
return (
|
|
<div className="flex flex-1 flex-col items-center justify-center gap-3 p-10 text-center">
|
|
<p className="text-muted-foreground">
|
|
{loaded ? `未找到发现 ${id}` : "加载中…"}
|
|
</p>
|
|
{loaded && (
|
|
<Button asChild variant="outline">
|
|
<Link href="/function/findings">
|
|
<ArrowLeftIcon /> 返回发现列表
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const title = finding.name || finding.vulnclass || "未分类";
|
|
|
|
return (
|
|
<Tabs
|
|
value={tab}
|
|
onValueChange={setTab}
|
|
className="flex flex-1 flex-col gap-0"
|
|
>
|
|
{/* Sticky header */}
|
|
<header className="sticky top-0 z-10 flex flex-col gap-2 border-b bg-background/95 px-4 py-2.5 backdrop-blur lg:px-6">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<SidebarTrigger className="-ml-1" />
|
|
<Button asChild variant="ghost" size="icon" className="size-7">
|
|
<Link href="/function/findings">
|
|
<ArrowLeftIcon />
|
|
</Link>
|
|
</Button>
|
|
<ShieldAlertIcon className="size-4 text-muted-foreground" />
|
|
<h1 className="max-w-md truncate text-sm font-semibold" title={title}>
|
|
{title}
|
|
</h1>
|
|
<code className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-muted-foreground">
|
|
#{finding.id}
|
|
</code>
|
|
<Separator orientation="vertical" className="mx-1 h-4" />
|
|
<StatusBadge domain="severity" value={finding.severity} dot />
|
|
<StatusBadge domain="finding" value={finding.status} dot />
|
|
</div>
|
|
<TabsList>
|
|
<TabsTrigger value="overview">概览</TabsTrigger>
|
|
<TabsTrigger value="lineage">链路图</TabsTrigger>
|
|
</TabsList>
|
|
</header>
|
|
|
|
{/* Tab content */}
|
|
<div className="flex-1 p-4 lg:p-6">
|
|
{/* 概览:左(摘要 + 证据)/ 右(状态区) */}
|
|
<TabsContent value="overview" className="mt-0">
|
|
<div className="grid gap-4 lg:grid-cols-3">
|
|
{/* 左栏 */}
|
|
<div className="flex flex-col gap-4 lg:col-span-2">
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-sm">摘要</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<p className="text-sm leading-relaxed whitespace-pre-wrap">
|
|
{finding.summary || "(无摘要)"}
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-sm">证据 / PoC</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{finding.evidence ? (
|
|
<pre className="max-h-[46vh] overflow-auto rounded-md bg-muted px-3 py-2 font-mono text-xs whitespace-pre-wrap">
|
|
{finding.evidence}
|
|
</pre>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">(无证据)</p>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
{/* 证据下方:详细报告(Markdown 渲染) */}
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-sm">详细报告</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{finding.report ? (
|
|
<Markdown text={finding.report} />
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">
|
|
暂无详细报告。
|
|
</p>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
|
|
{/* 右栏:状态区 */}
|
|
<Card className="h-fit lg:sticky lg:top-24">
|
|
<CardHeader>
|
|
<CardTitle className="text-sm">状态</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="divide-y">
|
|
{/* 漏洞 ID */}
|
|
<FieldRow label="漏洞 ID">
|
|
<code className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-muted-foreground">
|
|
#{finding.id}
|
|
</code>
|
|
</FieldRow>
|
|
|
|
{/* 严重等级(可改) */}
|
|
<FieldRow label="严重等级">
|
|
<Select
|
|
value={finding.severity}
|
|
onValueChange={(v) => changeSeverity(v as Severity)}
|
|
>
|
|
<SelectTrigger
|
|
size="sm"
|
|
className="h-7 w-auto border-none px-1 shadow-none focus-visible:ring-0"
|
|
>
|
|
<StatusBadge domain="severity" value={finding.severity} dot />
|
|
</SelectTrigger>
|
|
<SelectContent position="popper" align="end">
|
|
{SEVERITIES.map((sv) => (
|
|
<SelectItem key={sv} value={sv}>
|
|
{statusMeta("severity", sv).label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</FieldRow>
|
|
|
|
{/* 处理状态(可改) */}
|
|
<FieldRow label="处理状态">
|
|
<Select
|
|
value={finding.status}
|
|
onValueChange={(v) => changeStatus(v as FindingStatus)}
|
|
>
|
|
<SelectTrigger
|
|
size="sm"
|
|
className="h-7 w-auto border-none px-1 shadow-none focus-visible:ring-0"
|
|
>
|
|
<StatusBadge domain="finding" value={finding.status} dot />
|
|
</SelectTrigger>
|
|
<SelectContent position="popper" align="end">
|
|
{FINDING_STATUSES.map((st) => (
|
|
<SelectItem key={st} value={st}>
|
|
{statusMeta("finding", st).label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</FieldRow>
|
|
|
|
{/* 漏洞类型 */}
|
|
<FieldRow label="漏洞类型">
|
|
{finding.vulnclass ? (
|
|
<code className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs">
|
|
{finding.vulnclass}
|
|
</code>
|
|
) : (
|
|
<span className="text-muted-foreground">—</span>
|
|
)}
|
|
</FieldRow>
|
|
|
|
{/* 涉及资产 */}
|
|
<FieldRow label="涉及资产">
|
|
{finding.assets && finding.assets.length > 0 ? (
|
|
<div className="flex flex-wrap justify-end gap-1">
|
|
{finding.assets.map((a) => (
|
|
<code
|
|
key={a.id}
|
|
className="max-w-[16rem] truncate rounded bg-muted px-1.5 py-0.5 font-mono text-xs"
|
|
title={`${a.type} · ${a.label}`}
|
|
>
|
|
{a.label}
|
|
</code>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<span className="text-muted-foreground">—</span>
|
|
)}
|
|
</FieldRow>
|
|
|
|
{/* 所属任务 */}
|
|
<FieldRow label="所属任务">
|
|
{finding.task_id ? (
|
|
<Link
|
|
href={`/function/tasks/detail?id=${finding.task_id}`}
|
|
className="inline-flex max-w-[16rem] items-center gap-1 text-primary hover:underline"
|
|
title={finding.task_description}
|
|
>
|
|
<span className="truncate">
|
|
{finding.task_description || `#${finding.task_id}`}
|
|
</span>
|
|
<ArrowUpRightIcon className="size-3 shrink-0" />
|
|
</Link>
|
|
) : (
|
|
<span className="text-muted-foreground">—(任务已删除)</span>
|
|
)}
|
|
</FieldRow>
|
|
|
|
{/* 发现时间 */}
|
|
<FieldRow label="发现时间">
|
|
<span className="tabular-nums">{fmtTime(finding.ts)}</span>
|
|
</FieldRow>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</TabsContent>
|
|
|
|
{/* 链路图:从任务初始节点回溯到本漏洞节点的探索链路 */}
|
|
<TabsContent value="lineage" className="mt-0">
|
|
<Card>
|
|
<CardContent className="pt-6">
|
|
<FindingLineageView findingId={finding.id} />
|
|
</CardContent>
|
|
</Card>
|
|
</TabsContent>
|
|
</div>
|
|
</Tabs>
|
|
);
|
|
}
|
|
|
|
// useSearchParams must sit under a Suspense boundary for static export.
|
|
export default function FindingDetailPage() {
|
|
return (
|
|
<React.Suspense fallback={null}>
|
|
<FindingDetailInner />
|
|
</React.Suspense>
|
|
);
|
|
}
|