fix11: runtime contracts and smoke stability

This commit is contained in:
2026-04-30 21:50:03 +05:00
parent 4a0d9569d1
commit a41f14067b
10 changed files with 105 additions and 88 deletions
+19 -4
View File
@@ -74,13 +74,28 @@ function normalizeIpv4Host(name: string, value: string): string {
}
function normalizePublicHost(value: string): string {
if (!value) {
const host = value.trim();
if (!host) {
throw new Error("missing required HY2XS_PUBLIC_HOST");
}
if (value.includes(":")) {
throw new Error("HY2XS_PUBLIC_HOST must not contain IPv6");
if (host.includes("/") || host.includes(":") || /\s/.test(host)) {
throw new Error("HY2XS_PUBLIC_HOST must be a domain or IPv4 without scheme, port, path or spaces");
}
return value;
const ipv4 = /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/;
const domain = /^(?=.{1,253}$)([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,63}$/;
if (!ipv4.test(host) && !domain.test(host)) {
throw new Error(`invalid HY2XS_PUBLIC_HOST: ${value}`);
}
if (host === "0.0.0.0" || host === "127.0.0.1") {
throw new Error("HY2XS_PUBLIC_HOST must be a routable domain or public IPv4");
}
return host;
}
function normalizeTlsMode(value: string): TlsMode {