feat(findings): structured reproduction steps with per-step traffic bind

Align finding detail reproduction with AntiFox: store reproduction JSONB
(entry_point/prerequisites/steps/provenance), bind traffic via step_index,
syntax-highlight HTTP in steps/traffic panel, fall back to legacy evidence
when reproduction is absent. Old findings are not backfilled.
This commit is contained in:
MuCheng committed 2026-10-27 17:17:34 +08:00
1 parent a94b67ffd6
commit 93dc83165c
19 files changed
+493 -71

No files matched your search

@@ -11,6 +11,7 @@ import { toast } from "sonner";
import { CopyButton } from "@/components/copy-button";
import { FindingRetestPanel } from "@/components/finding-retest-panel";
import { FindingTrafficPanel } from "@/components/finding-traffic-panel";
import { FindingReproductionSection, hasStructuredReproduction } from "@/components/finding-reproduction-section";
import { Markdown } from "@/components/markdown";
import { StatusBadge } from "@/components/status-badge";
import { Alert, AlertDescription } from "@/components/ui/alert";
@@ -128,6 +129,7 @@ function FindingDetailInner() {
}
const title = finding.name || finding.vulnclass || "未分类";
const structuredReproduction = hasStructuredReproduction(finding.reproduction);
return (
<Tabs value={tab} onValueChange={setTab} className="flex flex-1 flex-col gap-0">
@@ -183,25 +185,36 @@ function FindingDetailInner() {
</CardContent>
</Card>
<FindingRetestPanel key={`retest:${id}`} findingId={id} readOnly={finding.inherited} onCompleted={load} />
<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>
{structuredReproduction && finding.reproduction ? (
<FindingReproductionSection
findingId={id}
reproduction={finding.reproduction}
contextTask={contextTaskId || undefined}
readOnly={finding.inherited}
onChanged={load}
/>
) : null}
<details open={!structuredReproduction} className="group">
<summary className="cursor-pointer list-none">
<Card>
<CardHeader><CardTitle className="text-sm">证据 / PoC</CardTitle></CardHeader>
</Card>
</summary>
<Card className="mt-2">
<CardContent className="pt-4">
{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>
</details>
<FindingTrafficPanel
key={`traffic:${id}`}
findingId={id}
contextTask={contextTaskId || undefined}
readOnly={finding.inherited}
stepIndex={structuredReproduction ? 0 : undefined}
title={structuredReproduction ? "未归入步骤的流量" : undefined}
onChanged={load}
/>
{/* 证据下方:详细报告(Markdown 渲染) */}
@@ -0,0 +1,116 @@
"use client";
import * as React from "react";
import { ExternalLinkIcon, PlusIcon } from "lucide-react";
import { HttpCodeBlock } from "@/components/http-code-block";
import { TrafficEvidenceViewer } from "@/components/traffic-evidence-viewer";
import { TrafficPickerDialog } from "@/components/traffic-picker-dialog";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { api } from "@/lib/api";
import type { FindingTraffic, Reproduction } from "@/lib/types";
export function hasStructuredReproduction(reproduction?: Reproduction | null) {
return Boolean(reproduction && ((reproduction.steps?.length ?? 0) > 0 || reproduction.entry_point));
}
export function FindingReproductionSection({
findingId,
reproduction,
contextTask,
readOnly,
onChanged,
}: {
findingId: string;
reproduction: Reproduction;
contextTask?: string;
readOnly?: boolean;
onChanged?: () => void;
}) {
const [traffic, setTraffic] = React.useState<FindingTraffic | null>(null);
const [pickerStep, setPickerStep] = React.useState<number | null>(null);
const [preview, setPreview] = React.useState<string | null>(null);
const [reload, setReload] = React.useState(0);
const load = React.useCallback(() => {
api.findingTraffic(findingId, contextTask).then(setTraffic).catch(() => setTraffic(null));
}, [findingId, contextTask]);
React.useEffect(() => load(), [load, reload]);
const steps = reproduction.steps ?? [];
const allBindings = traffic?.bindings ?? [];
return (
<Card>
<CardHeader>
<CardTitle className="text-sm">测试过程 / 复现</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
{reproduction.entry_point ? (
<div className="rounded-md border bg-muted/30 px-3 py-2 text-sm">
<span className="text-muted-foreground">入口:</span>
<code className="break-all font-mono">{reproduction.entry_point}</code>
</div>
) : null}
{(reproduction.prerequisites?.length ?? 0) > 0 ? (
<div className="rounded-md border bg-muted/30 px-3 py-2 text-sm">
<div className="text-muted-foreground">前置条件</div>
<ul className="ml-5 list-disc">
{reproduction.prerequisites?.map((item, index) => <li key={`${index}-${item}`}>{item}</li>)}
</ul>
</div>
) : null}
{steps.map((step, index) => {
const stepIndex = index + 1;
const bound = allBindings.filter((item) => (item.step_index ?? 0) === stepIndex);
return (
<div key={stepIndex} className="space-y-2 rounded-md border p-3">
<div className="flex flex-wrap items-center gap-2">
<Badge variant="secondary">步骤 {stepIndex}</Badge>
{step.expected ? <span className="text-sm">预期:{step.expected}</span> : null}
{step.proves ? <span className="text-sm text-muted-foreground">证明:{step.proves}</span> : null}
<div className="ml-auto flex gap-1">
{bound.map((item) => (
<Button key={item.id} variant="ghost" size="sm" className="h-7 text-xs" onClick={() => setPreview(item.id)}>
<ExternalLinkIcon className="size-3" /> 查看流量
</Button>
))}
{!readOnly ? (
<Button variant="outline" size="sm" className="h-7 text-xs" onClick={() => setPickerStep(stepIndex)}>
<PlusIcon className="size-3" /> 绑定流量
</Button>
) : null}
</div>
</div>
{step.request?.trim() ? <HttpCodeBlock raw={step.request} /> : null}
{step.response?.trim() ? (
<div>
<div className="mb-1 text-xs text-muted-foreground">响应</div>
<HttpCodeBlock raw={step.response} />
</div>
) : null}
{bound.length > 0 ? <div className="text-xs text-muted-foreground">已绑定 {bound.length} 条流量</div> : null}
</div>
);
})}
{reproduction.provenance ? <p className="text-xs text-muted-foreground">来源:{reproduction.provenance}</p> : null}
{pickerStep !== null ? (
<TrafficPickerDialog
findingId={findingId}
contextTask={contextTask}
bound={allBindings}
stepIndex={pickerStep}
onClose={() => setPickerStep(null)}
onBound={() => {
setPickerStep(null);
setReload((value) => value + 1);
onChanged?.();
}}
/>
) : null}
<TrafficEvidenceViewer findingId={findingId} bindingId={preview} contextTask={contextTask} onClose={() => setPreview(null)} />
</CardContent>
</Card>
);
}
+35 -4
View File
@@ -28,6 +28,7 @@ import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Skeleton } from "@/components/ui/skeleton";
import { Textarea } from "@/components/ui/textarea";
import { Input } from "@/components/ui/input";
import { api } from "@/lib/api";
import type { FindingTraffic, FindingTrafficBinding, TrafficEvidenceRole } from "@/lib/types";
@@ -43,11 +44,15 @@ export function FindingTrafficPanel({
contextTask,
readOnly,
onChanged,
stepIndex: filterStepIndex,
title,
}: {
findingId: string;
contextTask?: string;
readOnly?: boolean;
onChanged: () => void;
stepIndex?: number;
title?: string;
}) {
const [data, setData] = React.useState<FindingTraffic | null>(null);
const [error, setError] = React.useState("");
@@ -58,6 +63,7 @@ export function FindingTrafficPanel({
const [editing, setEditing] = React.useState<FindingTrafficBinding | null>(null);
const [role, setRole] = React.useState<TrafficEvidenceRole>("supporting");
const [note, setNote] = React.useState("");
const [selectedStepIndex, setSelectedStepIndex] = React.useState("0");
const [busy, setBusy] = React.useState(false);
const [reload, setReload] = React.useState(0);
// biome-ignore lint/correctness/useExhaustiveDependencies: retry token intentionally refreshes this request.
@@ -68,7 +74,13 @@ export function FindingTrafficPanel({
api
.findingTraffic(findingId, contextTask)
.then((value) => {
if (active) setData(value);
if (active) {
setData(
filterStepIndex === undefined
? value
: { ...value, bindings: value.bindings.filter((b) => (b.step_index ?? 0) === filterStepIndex) },
);
}
})
.catch((e: Error) => {
if (active) setError(e.message);
@@ -76,7 +88,7 @@ export function FindingTrafficPanel({
return () => {
active = false;
};
}, [findingId, contextTask, reload]);
}, [findingId, contextTask, reload, filterStepIndex]);
async function mutate(action: () => Promise<FindingTraffic>) {
setBusy(true);
@@ -131,7 +143,7 @@ export function FindingTrafficPanel({
<Card>
<CardHeader>
<div className="flex flex-wrap items-center justify-between gap-2">
<CardTitle>关联流量 {data ? `(${data.bindings.length})` : ""}</CardTitle>
<CardTitle>{title ?? "关联流量"} {data ? `(${data.bindings.length})` : ""}</CardTitle>
<div className="flex flex-wrap gap-2">
<Button
variant="outline"
@@ -216,6 +228,7 @@ export function FindingTrafficPanel({
setEditing(b);
setRole(b.role);
setNote(b.note);
setSelectedStepIndex(String(b.step_index ?? 0));
}}
>
编辑说明
@@ -262,6 +275,7 @@ export function FindingTrafficPanel({
findingId={findingId}
contextTask={contextTask}
bound={data.bindings}
stepIndex={Math.max(0, Number.parseInt(selectedStepIndex, 10) || 0)}
onClose={() => setAdding(false)}
onBound={() => {
setReload((n) => n + 1);
@@ -308,6 +322,17 @@ export function FindingTrafficPanel({
<FieldLabel htmlFor="evidence-note">证据说明</FieldLabel>
<Textarea id="evidence-note" value={note} onChange={(e) => setNote(e.target.value)} />
</Field>
<Field>
<FieldLabel htmlFor="evidence-step">复现步骤序号</FieldLabel>
<Input
id="evidence-step"
type="number"
min={0}
step={1}
value={selectedStepIndex}
onChange={(e) => setSelectedStepIndex(e.target.value)}
/>
</Field>
</FieldGroup>
<DialogFooter>
<Button variant="outline" disabled={busy} onClick={() => setEditing(null)}>
@@ -318,7 +343,13 @@ export function FindingTrafficPanel({
onClick={() => {
if (editing && data)
void mutate(() =>
api.editFindingTraffic(findingId, editing.id, data.version, { role, note }, contextTask),
api.editFindingTraffic(
findingId,
editing.id,
data.version,
{ role, note, step_index: Math.max(0, Number.parseInt(selectedStepIndex, 10) || 0) },
contextTask,
),
);
}}
>
@@ -30,12 +30,14 @@ export function TrafficPickerDialog({
findingId,
contextTask,
bound,
stepIndex,
onClose,
onBound,
}: {
findingId: string;
contextTask?: string;
bound: FindingTrafficBinding[];
stepIndex?: number;
onClose: () => void;
onBound: () => void;
}) {
@@ -91,6 +93,7 @@ export function TrafficPickerDialog({
findingId,
[...selected].map((traffic_id) => ({ traffic_id })),
contextTask,
stepIndex,
);
toast.success(`已绑定 ${selected.size} 条流量`);
onBound();
+3 -3
View File
@@ -714,16 +714,16 @@ export const api = {
get<FindingTraffic>(
`/exploration/findings/${id}/traffic${contextTask ? `?context_task=${encodeURIComponent(contextTask)}` : ""}`,
),
bindFindingTraffic: (id: string, traffic_refs: TrafficEvidenceRef[], contextTask?: string) =>
bindFindingTraffic: (id: string, traffic_refs: TrafficEvidenceRef[], contextTask?: string, step_index?: number) =>
post<FindingTraffic>(
`/exploration/findings/${id}/traffic${contextTask ? `?context_task=${encodeURIComponent(contextTask)}` : ""}`,
{ traffic_refs },
{ traffic_refs, ...(step_index !== undefined ? { step_index } : {}) },
),
editFindingTraffic: (
id: string,
bindingId: string,
version: number,
fields: { role: TrafficEvidenceRole; note: string },
fields: { role: TrafficEvidenceRole; note: string; step_index?: number },
contextTask?: string,
) =>
patch<FindingTraffic>(
+18
View File
@@ -512,6 +512,21 @@ export interface FindingAsset {
label: string;
}
export interface ReproStep {
request: string;
response?: string;
expected?: string;
proves?: string;
traffic_ids?: string[];
}
export interface Reproduction {
entry_point?: string;
prerequisites?: string[];
steps?: ReproStep[];
provenance?: string;
}
export interface Finding {
case_id?: string;
traffic_count?: number;
@@ -527,6 +542,7 @@ export interface Finding {
summary: string;
evidence: string;
report?: string; // 详细报告(Markdown);仅详情接口返回,列表为空
reproduction?: Reproduction | null;
intent_id?: string;
param_id?: string;
task_id?: string;
@@ -1604,6 +1620,7 @@ export interface TrafficEvidenceRef {
traffic_id: string;
role?: TrafficEvidenceRole;
note?: string;
step_index?: number;
}
export interface TrafficEvidenceSnapshot {
id: string;
@@ -1627,6 +1644,7 @@ export interface FindingTrafficBinding {
role: TrafficEvidenceRole;
note: string;
position: number;
step_index?: number;
created_at: string;
snapshot: TrafficEvidenceSnapshot;
}