mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-09 16:05:23 +02:00
* fix(domain): validate hostname format to reject invalid characters Underscores and other invalid characters were accepted in domain inputs with no validation, causing Let's Encrypt to silently fail certificate issuance while Dokploy fell back to a self-signed cert. Fixes #4716 * fix(create-server): update SSH key label for clarity in server creation form
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { VALID_HOSTNAME_REGEX } from "@dokploy/server";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
describe("VALID_HOSTNAME_REGEX", () => {
|
|
it.each([
|
|
"example.com",
|
|
"sub.example.com",
|
|
"bbn-client.example.com",
|
|
"a.b.c.example.co",
|
|
"xn--80ak6aa92e.com",
|
|
"123.example.com",
|
|
])("accepts valid hostname %s", (host) => {
|
|
expect(VALID_HOSTNAME_REGEX.test(host)).toBe(true);
|
|
});
|
|
|
|
it.each([
|
|
"bbn_client.example.com",
|
|
"-example.com",
|
|
"example-.com",
|
|
"example",
|
|
"exa mple.com",
|
|
"example..com",
|
|
"",
|
|
`a${"a".repeat(63)}.com`,
|
|
])("rejects invalid hostname %s", (host) => {
|
|
expect(VALID_HOSTNAME_REGEX.test(host)).toBe(false);
|
|
});
|
|
|
|
// IDNs (Cyrillic, German umlauts, etc.) must be submitted in their
|
|
// ACME/punycode form ("xn--...") — that's what Let's Encrypt issues
|
|
// certificates for, so raw Unicode labels are rejected here.
|
|
it.each(["пример.рф", "bücher.de", "日本語.jp"])(
|
|
"rejects raw unicode IDN %s",
|
|
(host) => {
|
|
expect(VALID_HOSTNAME_REGEX.test(host)).toBe(false);
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
"xn--e1afmkfd.xn--p1ai", // punycode for пример.рф
|
|
"xn--bcher-kva.de", // punycode for bücher.de
|
|
"xn--wgv71a119e.jp", // punycode for 日本語.jp
|
|
])("accepts punycode-encoded IDN %s", (host) => {
|
|
expect(VALID_HOSTNAME_REGEX.test(host)).toBe(true);
|
|
});
|
|
});
|