fix(monitors): bound certificate probe and gate client on scheme
Addresses review feedback on #3848. Timeout: the probe now dials a user-defined port, so it can reach a service that accepts the connection but never completes the TLS handshake, hanging the request indefinitely. ssl-checker already wires a "timeout" listener that rejects with "Timed Out", but its defaults set no timeout, so it never fired. Passing one activates it. The bundled type declaration is a hand-maintained subset of https.RequestOptions and omitted "timeout"; it is added there so the call typechecks against an option the library already supports. Client gating: "http" is a single monitor type covering both schemes, so an http:// monitor passed the existing type check and requested a certificate anyway. With the server now rejecting those, the details page would surface a 400 on every visit. The scheme is gated client side to match, and the stat box falls back to "N/A" as before. Test comment removed as requested; the timeout is covered by a new assertion in the same file.
This commit is contained in:
1 parent
25a7ac4877
commit
a672f7604d
4 files changed
+31
-8
No files matched your search
@@ -34,6 +34,17 @@ import { Typography } from "@mui/material";
|
||||
|
||||
const certificateDateFormat = "MMM D, YYYY h A";
|
||||
|
||||
const isHttpsUrl = (url?: string): boolean => {
|
||||
if (!url) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return new URL(url).protocol === "https:";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
interface CertificateResponse {
|
||||
certificateDate: string;
|
||||
}
|
||||
@@ -80,13 +91,15 @@ const UptimeDetailsPage = () => {
|
||||
const monitor = monitorData?.monitor;
|
||||
const monitorStats = monitorDetailsData?.monitorStats ?? null;
|
||||
|
||||
// Certificate fetch - only for HTTP monitors
|
||||
// Certificate fetch - only for monitors served over HTTPS. A "http" type
|
||||
// monitor may still have an http:// URL, which serves no certificate, so the
|
||||
// scheme is gated here to match the server rather than requesting a 400.
|
||||
const certificateUrl = useMemo(() => {
|
||||
if (!monitorId || monitor?.type !== "http") {
|
||||
if (!monitorId || monitor?.type !== "http" || !isHttpsUrl(monitor?.url)) {
|
||||
return null;
|
||||
}
|
||||
return `/monitors/certificate/${monitorId}`;
|
||||
}, [monitorId, monitor?.type]);
|
||||
}, [monitorId, monitor?.type, monitor?.url]);
|
||||
|
||||
const { data: certificateData } = useGet<CertificateResponse>(
|
||||
certificateUrl,
|
||||
|
||||
Reference in new issue
Block a user