import { useMemo, useState } from 'react'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { PLAN_LIMITS, type MonitoredPlugin, type VulnerabilityStatus } from '@cra-compliance/types'; import type { Page } from '../App'; import { useDashboardStats, useLimits } from '../hooks/useAccount'; import { useConfig, wpApiFetch, externalApiFetch, errorMessage } from '../hooks/useApi'; import { FINDINGS_KEY, useFindings } from '../hooks/useFindings'; import type { Findings } from '../hooks/useFindings'; import { useNotify } from '../hooks/useNotify'; import type { Vulnerability } from '../lib/types'; import { isOpen } from '../lib/types'; import { copyText, csvCell, downloadText } from '../lib/files'; import { dateOnly, dateTime, plural, relative } from '../lib/format'; import { LINKS } from '../content/links'; import { SAVED_SCAN_EVERY } from '../content/plans'; import { PlanTable } from '../components/PlanTable'; import { NEW_INCIDENT_KEY } from './IncidentCenter'; import { ApiErrorNotice, Chip, Cite, Empty, ErrorState, ExternalLink, Mark, Notice, PageHead, Panel, Severity, Skel, severityText } from '../components/ui'; interface InstalledPlugin { slug: string; name: string; version: string; author: string; } type StatusFilter = 'active' | 'all' | VulnerabilityStatus; const STATUS_LABELS: Record = { open: 'Open', acknowledged: 'Acknowledged', in_progress: 'In progress', resolved: 'Resolved', false_positive: 'Not affected', }; const SEVERITY_RANK: Record = { critical: 0, high: 1, medium: 2, low: 3, info: 4 }; export function Scanner({ onNavigate }: { onNavigate: (page: Page) => void }) { const config = useConfig(); if (!config.connected) return ; return ; } function ScannerIntro({ onNavigate }: { onNavigate: (page: Page) => void }) { return (
onNavigate('settings')}>Connect an account} />
  • Choose plugins from this site or add any WordPress.org plugin by its slug.
  • Each plugin and version is checked against the WPScan vulnerability database on a schedule, and whenever you run a scan.
  • Findings show severity, CVE, affected versions and the version that fixes them. You track each one to resolved or not affected.
  • Vulnerabilities with evidence of exploitation in the wild are flagged so you can decide whether Article 14 reporting applies.
Annex I, Part I(2)(a)
Make products available without known exploitable vulnerabilities.
Annex I, Part II(1)
Identify and document vulnerabilities and components, including third-party ones.
Annex I, Part II(2)
Address and fix vulnerabilities without delay.
Art. 14(2)
Report an actively exploited vulnerability in your product: early warning within 24 hours.
Pricing} flush >

When you connect, the plugin sends your API key, this site's address, and the slugs and versions of the plugins you choose to monitor to the ResilienceWP API.{' '} Privacy policy

); } function Monitoring({ onNavigate }: { onNavigate: (page: Page) => void }) { const config = useConfig(); const queryClient = useQueryClient(); const { confirm, toast, NotifyPortal } = useNotify(); const stats = useDashboardStats(); const limits = useLimits(); const [showAdd, setShowAdd] = useState(false); const [selectedPlugins, setSelectedPlugins] = useState>(new Set()); const [selectedVulns, setSelectedVulns] = useState>(new Set()); const [scanning, setScanning] = useState>(new Set()); const [statusFilter, setStatusFilter] = useState('active'); const [collapsed, setCollapsed] = useState>(new Set()); const [error, setError] = useState(null); const pluginsQuery = useQuery({ queryKey: ['monitored-plugins'], queryFn: async () => (await externalApiFetch<{ data: MonitoredPlugin[] }>('/api/plugins')).data ?? [], staleTime: 60_000, }); const vulnsQuery = useFindings(); const installedQuery = useQuery({ queryKey: ['installed-plugins'], queryFn: async () => (await wpApiFetch<{ data: InstalledPlugin[] }>('installed-plugins')).data ?? [], staleTime: 5 * 60_000, }); const refreshAll = async () => { await Promise.all([ queryClient.invalidateQueries({ queryKey: ['monitored-plugins'] }), queryClient.invalidateQueries({ queryKey: FINDINGS_KEY }), queryClient.invalidateQueries({ queryKey: ['dashboard'] }), ]); }; const removePlugin = useMutation({ mutationFn: async (pluginId) => { await externalApiFetch('/api/plugins', { method: 'DELETE', body: JSON.stringify({ plugin_id: pluginId }) }); }, onSuccess: async (_data, pluginId) => { // The service deletes the plugin's findings with it. queryClient.setQueryData(FINDINGS_KEY, (current) => current && { ...current, items: current.items.filter((v) => v.plugin_id !== pluginId), }); setSelectedPlugins(new Set()); await refreshAll(); toast({ message: 'Plugin removed from monitoring.' }); }, onError: (err) => setError(err), }); const updateStatus = useMutation({ mutationFn: async ({ ids, status }) => { await Promise.all(ids.map((id) => externalApiFetch('/api/vulnerabilities', { method: 'PATCH', body: JSON.stringify({ vulnerability_id: id, status }), }))); }, onSuccess: async (_data, { ids, status }) => { setSelectedVulns(new Set()); await refreshAll(); if (ids.length > 1) toast({ message: `${ids.length} findings marked ${STATUS_LABELS[status].toLowerCase()}.` }); }, onError: (err) => setError(err), }); const scan = async (ids: string[]) => { setScanning(new Set(ids)); setError(null); let done = 0; try { if (ids.length > 1 && ids.length === plugins.length) { // Everything is selected: one request scans the whole list. const res = await externalApiFetch<{ data?: BatchScanResult }>('/api/scan', { method: 'POST', body: JSON.stringify({ action: 'scan_all_plugins' }), }); // `scanned` counts every plugin the service took on, including the // ones it could not check. It stops at the month's allowance. const taken = Math.min(res.data?.scanned ?? 0, ids.length); const notChecked = Math.min(res.data?.not_checked ?? 0, taken); const left = ids.length - taken; done = taken - notChecked; if (left === 0 && notChecked === 0) { toast({ message: `${done} scans finished.` }); } else { const parts = [`${done} of ${ids.length} plugins scanned.`]; if (notChecked > 0) parts.push(`${plural(notChecked, 'plugin', 'plugins')} could not be checked because the vulnerability database did not answer. Try again later.`); if (left > 0) parts.push(`${plural(left, 'plugin was', 'plugins were')} not scanned because the scans your plan includes this month are used up.`); toast({ message: parts.join(' '), type: 'error' }); } } else { // One at a time: the service accepts ten scan requests a minute. let recent = 0; for (const id of ids) { const res = await externalApiFetch<{ data?: SingleScanResult }>('/api/scan', { method: 'POST', body: JSON.stringify({ plugin_id: id }), }); done += 1; if (res.data?.skipped) recent += 1; setScanning((current) => { const next = new Set(current); next.delete(id); return next; }); } if (ids.length === 1) { toast({ message: recent ? 'This plugin was scanned in the last five minutes. The results are current.' : 'Scan finished.' }); } else { toast({ message: recent ? `${done} scans finished. ${recent} of them ran in the last five minutes, so those results were already current.` : `${done} scans finished.` }); } } } catch (err) { setError(ids.length > 1 && done > 0 ? `${done} of ${ids.length} plugins were scanned, then this stopped. ${errorMessage(err, 'The scan failed.')}` : err ?? 'The scan failed.'); } await refreshAll(); setScanning(new Set()); setSelectedPlugins(new Set()); }; const startIncident = (vuln: Vulnerability) => { try { window.sessionStorage.setItem(NEW_INCIDENT_KEY, JSON.stringify({ vulnerability_id: vuln.id, plugin_id: vuln.plugin_id, title: vuln.title })); } catch { /* ignore */ } onNavigate('incidents'); }; const plugins = pluginsQuery.data ?? []; const vulns = useMemo(() => vulnsQuery.data?.items ?? [], [vulnsQuery.data]); // Until the findings have loaded, a plugin's row must not say it is clear. const findingsReady = vulnsQuery.isSuccess; const installed = installedQuery.data ?? []; const pluginById = useMemo(() => new Map(plugins.map((p) => [p.id, p])), [plugins]); const installedVersion = useMemo(() => new Map(installed.map((p) => [p.slug, p.version])), [installed]); const filtered = vulns.filter((v) => { if (statusFilter === 'active') return isOpen(v); if (statusFilter === 'all') return true; return v.status === statusFilter; }); const groups = useMemo(() => { const byPlugin = new Map(); for (const v of filtered) { byPlugin.set(v.plugin_id, [...(byPlugin.get(v.plugin_id) ?? []), v]); } for (const list of byPlugin.values()) { list.sort((a, b) => { const exploited = Number(Boolean(b.actively_exploited)) - Number(Boolean(a.actively_exploited)); if (exploited !== 0) return exploited; const rank = (SEVERITY_RANK[a.severity] ?? 5) - (SEVERITY_RANK[b.severity] ?? 5); if (rank !== 0) return rank; return Date.parse(b.discovered_at ?? '') - Date.parse(a.discovered_at ?? ''); }); } return Array.from(byPlugin.entries()).sort(([, a], [, b]) => { const score = (list: Vulnerability[]) => Math.min(...list.map((v) => (v.actively_exploited ? -1 : SEVERITY_RANK[v.severity] ?? 5))); return score(a) - score(b); }); }, [filtered]); const openVulns = vulns.filter(isOpen); const openByPlugin = useMemo(() => { const map = new Map(); for (const v of vulns) { if (isOpen(v)) map.set(v.plugin_id, [...(map.get(v.plugin_id) ?? []), v]); } return map; }, [vulns]); const exploitedOpen = openVulns.filter((v) => v.actively_exploited); const atLimit = plugins.length >= limits.max_plugins; const loadError = pluginsQuery.error || vulnsQuery.error; const exportCsv = () => { const header = ['plugin', 'title', 'severity', 'severity_estimated', 'status', 'cve_id', 'cvss_score', 'actively_exploited', 'affected_versions', 'fixed_in_version', 'discovered_at']; const rows = filtered.map((v) => [ pluginById.get(v.plugin_id)?.name ?? '', v.title, v.severity, v.severity_estimated ? 'yes' : 'no', v.status, v.cve_id, v.cvss_score, v.actively_exploited ? 'yes' : 'no', v.affected_versions, v.fixed_in_version, v.discovered_at, ].map(csvCell).join(',')); // The byte order mark makes Excel read the file as UTF-8. downloadText(`\uFEFF${[header.join(','), ...rows].join('\r\n')}\r\n`, `vulnerabilities-${new Date().toISOString().slice(0, 10)}.csv`, 'text/csv'); }; const copySummary = async () => { const lines = filtered.filter(isOpen).map((v) => { const plugin = pluginById.get(v.plugin_id)?.name ?? 'Unknown plugin'; const parts = [`${plugin}: ${v.title}`, severityText(v.severity, v.severity_estimated)]; if (v.cve_id) parts.push(v.cve_id); if (v.actively_exploited) parts.push('actively exploited'); parts.push(v.fixed_in_version ? `fixed in ${v.fixed_in_version}` : 'no fix yet'); return `- ${parts.join(', ')}`; }); const ok = await copyText(lines.length ? lines.join('\n') : 'No open vulnerabilities.'); toast({ message: ok ? 'Summary copied.' : 'Copying is blocked in this browser. Use Export CSV instead.', type: ok ? 'info' : 'error' }); }; const scheduleText = stats.data?.next_scan_at ? `Next scheduled scan ${dateTime(stats.data.next_scan_at)}.` : `An automatic scan is saved to your scan history ${SAVED_SCAN_EVERY[limits.scan_frequency]}.`; return (
setShowAdd((v) => !v)} disabled={atLimit && !showAdd} title={atLimit ? `Your plan monitors up to ${plural(limits.max_plugins, 'plugin', 'plugins')}` : undefined} > {showAdd ? 'Close' : 'Add plugins'} } /> {error !== null && setError(null)} />} {loadError && ( { void pluginsQuery.refetch(); void vulnsQuery.refetch(); }} /> )} {exploitedOpen.length > 0 && (

If one is exploitable in a product you make, the 24-hour early warning under CRA Article 14 may apply.{' '} Record your reporting decisions in your dashboard

)} {atLimit && !showAdd && (

You are monitoring {plugins.length} of {plural(limits.max_plugins, 'plugin', 'plugins')} on the {config.plan.charAt(0).toUpperCase() + config.plan.slice(1)} plan.{' '} {config.plan !== 'pro' && Compare plans}

)} {showAdd && ( p.slug))} remaining={Math.max(0, limits.max_plugins - plugins.length)} onAdded={async (count) => { setShowAdd(false); await refreshAll(); toast({ message: count === 1 ? 'Plugin added. Run a scan to check it now.' : `${count} plugins added. Run a scan to check them now.` }); }} /> )} 0 && ( <> {selectedPlugins.size > 0 && ( )} ) } flush > {pluginsQuery.isLoading ? (
{[0, 1, 2].map((i) => )}
) : plugins.length === 0 ? ( setShowAdd(true)}>Add plugins} > Add the plugins you make, and the plugins they depend on. ) : (
{plugins.map((plugin) => { const open = openByPlugin.get(plugin.id) ?? []; const exploited = open.some((v) => v.actively_exploited); const local = installedVersion.get(plugin.slug); const isScanning = scanning.has(plugin.id); return ( ); })}
setSelectedPlugins(selectedPlugins.size === plugins.length ? new Set() : new Set(plugins.map((p) => p.id)))} /> Plugin Status Last scan Actions
setSelectedPlugins((current) => { const next = new Set(current); if (next.has(plugin.id)) next.delete(plugin.id); else next.add(plugin.id); return next; })} /> {plugin.name} {plugin.slug}@{plugin.version} {local && local !== plugin.version && ( Version {local} is installed here. The monitored version is updated to it automatically within a few minutes, and then scanned. )} {isScanning ? ( ) : !plugin.last_scanned_at ? ( ) : !findingsReady ? ( ) : open.length > 0 ? ( ) : plugin.status === 'version_unknown' ? ( ) : plugin.status === 'not_found' ? ( ) : ( )} {plugin.last_scanned_at ? relative(plugin.last_scanned_at) : 'Never'}
)}
} flush > {vulnsQuery.isLoading ? (
{[0, 1, 2].map((i) => )}
) : !findingsReady ? ( Until they load, this page cannot say whether a plugin has open findings. Use Try again above. ) : vulns.length === 0 ? ( {plugins.length === 0 ? 'Add plugins and run a scan. Findings appear here.' : 'None of your monitored plugins has a known vulnerability. Scans continue on schedule.'} ) : filtered.length === 0 ? ( ) : ( <>
{selectedVulns.size > 0 && (
)}
{groups.map(([pluginId, list]) => { const plugin = pluginById.get(pluginId); const isCollapsed = collapsed.has(pluginId); const critical = list.filter((v) => v.severity === 'critical').length; const exploited = list.filter((v) => v.actively_exploited).length; return (
{!isCollapsed && list.map((vuln) => ( setSelectedVulns((current) => { const next = new Set(current); if (next.has(vuln.id)) next.delete(vuln.id); else next.add(vuln.id); return next; })} onStatus={(status) => updateStatus.mutate({ ids: [vuln.id], status })} onReport={() => startIncident(vuln)} /> ))}
); })} )}
); } /** POST /api/scan with a plugin_id. `skipped` means it was scanned in the last five minutes. */ interface SingleScanResult { skipped?: boolean; } /** POST /api/scan with action scan_all_plugins. */ interface BatchScanResult { scanned?: number; not_checked?: number; } function nextStep(vuln: Vulnerability): string { if (vuln.status === 'resolved') return 'Resolved.'; if (vuln.status === 'false_positive') return 'Marked as not affecting your product.'; if (vuln.actively_exploited === true) { return vuln.fixed_in_version ? `Update to ${vuln.fixed_in_version} or later now.` : 'No fixed version yet. Apply a mitigation or stop using the plugin until a fix is released.'; } if (vuln.fixed_in_version) return `Update to ${vuln.fixed_in_version} or later, then mark it resolved.`; return 'No fixed version yet. Assess the risk and apply a mitigation, or mark it not affected if it does not apply to how you use the plugin.'; } function VulnRow({ vuln, selected, canReport, busy, onSelect, onStatus, onReport }: { vuln: Vulnerability; selected: boolean; canReport: boolean; busy: boolean; onSelect: () => void; onStatus: (status: VulnerabilityStatus) => void; onReport: () => void; }) { const statusId = `rwp-status-${vuln.id}`; return (

{vuln.title}

{vuln.actively_exploited === true && Actively exploited} {vuln.actively_exploited === true && vuln.known_ransomware === true && Used in ransomware campaigns} {vuln.cve_id && ( {vuln.cve_id} )} {vuln.cvss_score != null && CVSS {vuln.cvss_score}} {vuln.affected_versions && Affects {vuln.affected_versions}} {vuln.fixed_in_version ? Fixed in {vuln.fixed_in_version} : No fix yet} {vuln.discovered_at && Found {dateOnly(vuln.discovered_at)}} {!isOpen(vuln) && vuln.still_reported_at && ( Still reported by the scanner )}

{nextStep(vuln)}

{vuln.actively_exploited === true && }
{canReport && isOpen(vuln) && ( )}
); } function AddPlugins({ installed, installedLoading, monitoredSlugs, remaining, onAdded }: { installed: InstalledPlugin[]; installedLoading: boolean; monitoredSlugs: Set; remaining: number; onAdded: (count: number) => Promise; }) { const [mode, setMode] = useState<'installed' | 'slug'>('installed'); const [selected, setSelected] = useState>(new Set()); const [slug, setSlug] = useState(''); const [name, setName] = useState(''); const [version, setVersion] = useState(''); const [error, setError] = useState(null); const available = installed.filter((p) => !monitoredSlugs.has(p.slug)); const add = useMutation>({ mutationFn: async (items) => { await Promise.all(items.map((item) => externalApiFetch('/api/plugins', { method: 'POST', body: JSON.stringify(item) }))); return items.length; }, onSuccess: async (count) => { setSelected(new Set()); setSlug(''); setName(''); setVersion(''); await onAdded(count); }, onError: (err) => setError(err), }); const submitSlug = () => { const clean = slug.trim().toLowerCase(); if (!/^[a-z0-9-]+$/.test(clean)) { setError('A slug uses lowercase letters, numbers and hyphens, like the end of wordpress.org/plugins/your-plugin.'); return; } setError(null); add.mutate([{ slug: clean, name: name.trim() || clean, version: version.trim() || '0.0.0' }]); }; const tooMany = selected.size > remaining; return ( } >
{error !== null && } {mode === 'installed' ? ( installedLoading ? (
{[0, 1, 2].map((i) => )}
) : available.length === 0 ? (

Every plugin installed on this site is already monitored.

) : ( <>
    {available.map((p) => (
  • ))}
{tooMany && Your plan allows {plural(remaining, 'more plugin', 'more plugins')}.}
) ) : (
{ e.preventDefault(); submitSlug(); }} noValidate>
setSlug(e.target.value)} placeholder="woocommerce" autoComplete="off" spellCheck={false} /> The last part of the plugin's address on WordPress.org. Use this for plugins your product depends on.
setName(e.target.value)} />
setVersion(e.target.value)} placeholder="9.4.2" />
)}
); } /** Exploitation evidence from the API. Missing fields are treated as "not exploited". */ function ExploitedNote({ vuln }: { vuln: Vulnerability }) { const kev = !vuln.exploited_source || vuln.exploited_source === 'cisa_kev'; const decision = vuln.reporting_decision; return (

{kev ? 'Listed in CISA’s known-exploited catalog. If it is exploitable in your product, the 24-hour early warning under CRA Article 14 may apply.' : 'There is evidence this is being exploited. If it is exploitable in your product, the 24-hour early warning under CRA Article 14 may apply.'} {' '} {decision === 'reported' ? ( Recorded as reported. ) : decision === 'not_affected' ? ( Recorded as not affecting your product. ) : null}{' '} {decision === 'reported' || decision === 'not_affected' ? 'View the decision in your dashboard' : 'Record your reporting decision in your dashboard'}

); }