fix(monitors): check TLS certificate on the monitor's own port
fetchMonitorCertificate parsed the monitor URL but passed only the hostname to ssl-checker, which then defaulted to 443. A monitor on a non-standard port such as https://host:54321 therefore had the certificate of whatever answered on 443 inspected instead of its own, surfacing as "N/A" in the certificate expiry box when nothing was listening there. URL.port is an empty string for default ports, so it is mapped to 443 explicitly rather than passed through Number(), which would have yielded NaN. ssl-checker already accepts the port via SSLOptions, so no dependency or signature change is needed. Adds a regression suite covering the reported case (non-standard port), the default-port fallback, an explicit :443, and the NaN guard. Verified by reverting the fix: the three port assertions fail without it. Fixes #3646
This commit is contained in:
1 parent
959a434d21
commit
f74d1d53f6
2 files changed
+84
-1
No files matched your search
@@ -7,10 +7,15 @@ import { parse as parseDomain } from "tldts";
|
||||
type SSLCheckerType = typeof sslChecker;
|
||||
type WhoisModule = typeof whoiser;
|
||||
|
||||
const DEFAULT_HTTPS_PORT = 443;
|
||||
|
||||
export const fetchMonitorCertificate = async (checker: SSLCheckerType, monitor: Monitor): Promise<SSLDetails> => {
|
||||
const monitorUrl = new URL(monitor.url);
|
||||
const hostname = monitorUrl.hostname;
|
||||
const cert = await checker(hostname);
|
||||
// URL.port is "" for default ports, so fall back to 443; without this the
|
||||
// certificate of a monitor on a non-standard port was probed on 443.
|
||||
const port = monitorUrl.port === "" ? DEFAULT_HTTPS_PORT : Number(monitorUrl.port);
|
||||
const cert = await checker(hostname, { port });
|
||||
if (cert?.validTo === null || cert?.validTo === undefined) {
|
||||
throw new Error("Certificate not found");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user