caelum0x 514086bdda feat: Phase 3 enterprise hardening — gateway chain, XDR threat detection, compliance ops, plan tiers
- lib/security/gatewayChain.ts: composable ordered front-door (ip-allowlist -> authN -> authZ ->
  provenance -> rate/quota) as an additive primitive + docs/gateway-rollout.md (BUILD not fork Envoy)
- XDR: 0064 security_events + lib/security/threatDetection.ts (4 deterministic detectors) +
  securityScan + /console/admin/security dashboard
- Compliance ops: retention purge (with SQL-identifier guard), nightly chain-integrity verifyChain,
  access-review snapshot; folded into the daily /api/cron/tick (one Vercel-Hobby cron)
- Plan tiers: 0065 Researcher/Team/Pharma-Enterprise + plan_features entitlements + requireFeature +
  /console/billing/tier (Part-11 e-sign, audit export, SSO/SCIM gated to Enterprise)
- docs/compliance-controls.md (SOC2/HIPAA/21 CFR Part 11 controls matrix)
- Fixed: honest new-active-key threat description; removed duplicate /security page

migrations 0064/0065/0066 applied to Neon; tsc + build green.
2026-07-11 00:18:36 +03:00

114 lines
3.6 KiB
TypeScript

"use client";
import { useCallback, useEffect, useState } from "react";
import { getJson } from "@/components/admin-audit/apiClient";
import { useCurrentRole } from "@/components/org-team/useCurrentRole";
import { AdminNoAccess } from "../_components/AdminNoAccess";
import {
SecurityEventFeed,
type SecurityEventItem,
} from "./_components/SecurityEventFeed";
import {
SeverityFilter,
type SeverityFilterValue,
} from "./_components/SeverityFilter";
import type { Severity } from "./_components/SeverityBadge";
// Threat-detection ("XDR") dashboard. Reads the org's deterministic security
// findings from /api/security/events and renders a severity-filterable feed.
// Any member (viewer+) may read: the API enforces viewer role, and the UI shows
// a read-only feed of findings that carry only ids/counts — never raw text.
interface SecurityEventsResponse {
events: SecurityEventItem[];
severityCounts: Record<Severity, number>;
}
const EMPTY_COUNTS: Record<Severity, number> = {
low: 0,
medium: 0,
high: 0,
critical: 0,
};
export default function SecurityDashboardPage() {
const { loading: roleLoading, role } = useCurrentRole();
// Any authenticated org member (viewer+) can read the feed.
const canView = role !== null;
const [events, setEvents] = useState<SecurityEventItem[]>([]);
const [counts, setCounts] = useState<Record<Severity, number>>(EMPTY_COUNTS);
const [total, setTotal] = useState(0);
const [filter, setFilter] = useState<SeverityFilterValue>("all");
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const load = useCallback(async (severity: SeverityFilterValue) => {
setLoading(true);
setError(null);
const query = severity === "all" ? "" : `?severity=${severity}`;
const res = await getJson<SecurityEventsResponse>(
`/api/security/events${query}`
);
if (!res.success || !res.data) {
setError(res.error ?? "Failed to load security events.");
setLoading(false);
return;
}
setEvents(res.data.events);
setCounts(res.data.severityCounts);
setTotal(res.meta?.total ?? res.data.events.length);
setLoading(false);
}, []);
useEffect(() => {
if (!roleLoading && canView) {
void load(filter);
} else if (!roleLoading) {
setLoading(false);
}
}, [roleLoading, canView, filter, load]);
if (!roleLoading && !canView) {
return (
<AdminNoAccess
title="Security"
message="You need to be a member of this organization to view security events."
/>
);
}
// The "all" total for the filter is the sum of every band's lifetime count,
// independent of the current page/filter, so the segmented control is stable.
const allTotal =
counts.low + counts.medium + counts.high + counts.critical;
return (
<div>
<h1 className="text-2xl font-semibold text-ink/80">Security</h1>
<p className="mt-1 text-sm text-ink/40">
Threat detection across this organization&apos;s API telemetry. Findings
are generated by deterministic detectors — no claim or patient text is
ever recorded.
</p>
<div className="mt-6">
<SeverityFilter
value={filter}
counts={counts}
total={allTotal}
onChange={setFilter}
/>
</div>
{filter !== "all" && !loading ? (
<p className="mt-3 text-xs text-ink/40 tabular-nums">
Showing {total} {filter} event{total === 1 ? "" : "s"}.
</p>
) : null}
<SecurityEventFeed events={events} loading={loading} error={error} />
</div>
);
}