import { analyzeHeaders, unavailableHeaderPosture, type HeaderControlStatus, type HeaderMap } from "@/lib/inspect/headers"; import { statusForHttp } from "@/lib/inspect/http-status"; import { CopyIcon, collectorLabel, collectorMeta, compact, finiteNumber, formatCertificateName, formatMxRecords, hasValue, isRecord, terminalHttpsResult, triState, } from "./report-utils"; type CopyHandler = (label: string, value: string) => void; function EvidenceValue({ label, value, onCopy }: { label: string; value: unknown; onCopy: CopyHandler }) { const text = label === "MX" ? formatMxRecords(value) : compact(value); return
{text}
; } export function CollectorState({ value, label }: { value: Record; label: string }) { const meta = collectorMeta(value); return
{label}{collectorLabel(meta.status)}
{meta.errors.length ? :

No collector errors recorded.

}
; } export function DnsEvidence({ dns, highlightedEvidence, onCopy }: { dns: Record; highlightedEvidence: string | null; onCopy: CopyHandler }) { const rows: Array<[string, unknown]> = [["A", dns.a], ["AAAA", dns.aaaa], ["MX", dns.mx], ["NS", dns.ns], ["TXT", dns.txt], ["SPF", dns.spf], ["DMARC", dns.dmarc]]; const spfPosture = isRecord(dns.spfPosture) ? dns.spfPosture : null; const dmarcPosture = isRecord(dns.dmarcPosture) ? dns.dmarcPosture : null; return

DNS records

{rows.map(([label, value]) =>
{label}
)}

Parsed mail posture

SPF
{compact(spfPosture?.status ?? dns.spf)}
SPF terminal all
{compact(spfPosture?.allQualifier ?? "Unavailable")}
DMARC
{compact(dmarcPosture?.status ?? dns.dmarc)}
Policy
{compact(dmarcPosture?.policy ?? "Unavailable")}
Records
{Array.isArray(dns.dmarc) ? dns.dmarc.length : 0} DMARC / {Array.isArray(dns.spf) ? dns.spf.length : 0} SPF
; } export function TlsEvidence({ tls, highlightedEvidence }: { tls: Record; highlightedEvidence: string | null }) { const attempts = Array.isArray(tls.attempts) ? tls.attempts : []; const status = collectorMeta(tls).status; return

Certificate

Protocol
{compact(tls.protocol)}
Endpoint
{compact(tls.address)}
Authorized
{triState(tls.authorized, status !== "failed")}
Hostname match
{triState(tls.hostnameValid, status !== "failed")}
Issuer
{formatCertificateName(tls.issuer)}
Subject
{formatCertificateName(tls.subject)}
SANs
{compact(tls.subjectaltname)}
Valid from
{compact(tls.validFrom)}
Valid to
{compact(tls.validTo)}
Days remaining
{finiteNumber(tls.daysRemaining) ? `${tls.daysRemaining} days` : "Unavailable"}
Fingerprint
{compact(tls.fingerprint256)}

Connection attempts

{attempts.length ?
    {attempts.map((attempt, index) =>
  • {compact(isRecord(attempt) ? attempt.address : null)}{compact(isRecord(attempt) ? attempt.error : attempt)}
  • )}
:

The first validated endpoint completed the TLS handshake.

}
; } function controlTone(status: HeaderControlStatus) { return status === "strong" || status === "good" ? "good" : status === "unavailable" ? "muted" : "warning"; } export function HttpEvidence({ http, highlightedEvidence }: { http: Record; highlightedEvidence: string | null }) { const terminal = terminalHttpsResult(http); const headers = terminal && isRecord(terminal.headers) ? terminal.headers as HeaderMap : null; const chain = Array.isArray(http.httpsChain) ? http.httpsChain.filter(isRecord) : []; const plain = isRecord(http.http) ? http.http : null; const plainStatus = statusForHttp(plain?.status); const posture = headers ? analyzeHeaders(headers) : unavailableHeaderPosture(); const redirectHops = [plain, ...chain].filter((hop): hop is Record => hop !== null && hasValue(hop.url)); const observedPlain = plain !== null && !("error" in plain); const observedRedirectTarget = isRecord(http.httpRedirectTarget) && "validated" in http.httpRedirectTarget; const labels: Record = { hsts: "HSTS", csp: "CSP", nosniff: "Nosniff", "referrer-policy": "Referrer-Policy", "frame-protection": "Frame protection" }; const headerNames = ["strict-transport-security", "content-security-policy", "x-content-type-options", "referrer-policy", "x-frame-options"]; return

Redirect path

HTTP to HTTPS

{plainStatus.label}
{redirectHops.length ?
    {redirectHops.map((hop, index) =>
  1. {index + 1}
    {String(hop.url).startsWith("https:") ? "HTTPS" : "HTTP"}{compact(hop.url)}{hasValue(hop.address) && Validated endpoint · {String(hop.address)}}
    {"error" in hop ? compact(hop.code ?? "Error") : `HTTP ${compact(hop.status)}`}
    {index < redirectHops.length - 1 && }
  2. )}
:

No HTTP(S) response was recorded.

}
Validated target
{triState(isRecord(http.httpRedirectTarget) ? http.httpRedirectTarget.validated : undefined, observedRedirectTarget)}
HTTPS redirect
{triState(http.httpRedirectsToHttps, observedPlain)}
{http.httpsDowngrade === true &&

HTTPS downgrade blocked before the HTTP target was requested.

}

Final HTTPS response

Security header posture

{posture.aggregate.label}
{posture.controls.map((control) =>
{labels[control.id]}{control.status}{control.reason}
)}
{headers ?
Show normalized header evidence
    {headerNames.map((name) =>
  • {name}{compact(headers[name])}
  • )}
:

No terminal HTTPS response; controls are unavailable rather than missing.

}
; }