fix(server): auto-bind 0.0.0.0 when allowedHosts includes a reverse-proxy domain
CI / build (push) Waiting to run
CI / build (push) Waiting to run
This commit is contained in:
+22
-7
@@ -160,20 +160,35 @@ export async function buildApp() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasExternalAllowedHost(allowedHostsRaw: string): boolean {
|
||||||
|
const tokens = allowedHostsRaw
|
||||||
|
.split(/[,\s]+/)
|
||||||
|
.map((t) => extractHostname(t))
|
||||||
|
.filter(Boolean);
|
||||||
|
return tokens.some(
|
||||||
|
(t) => t !== "localhost" && t !== "127.0.0.1" && t !== "::1" && t !== "[::1]",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function loadPersistedServerSysConfig(): PersistedServerSysConfig {
|
function loadPersistedServerSysConfig(): PersistedServerSysConfig {
|
||||||
try {
|
try {
|
||||||
if (existsSync(sysConfigPath)) {
|
if (existsSync(sysConfigPath)) {
|
||||||
const raw = JSON.parse(readFileSync(sysConfigPath, "utf8")) as Partial<PersistedServerSysConfig>;
|
const raw = JSON.parse(readFileSync(sysConfigPath, "utf8")) as Partial<PersistedServerSysConfig>;
|
||||||
|
const allowedHosts =
|
||||||
|
typeof raw.allowedHosts === "string" && raw.allowedHosts.trim()
|
||||||
|
? raw.allowedHosts.trim()
|
||||||
|
: "localhost, 127.0.0.1";
|
||||||
|
const rawHost =
|
||||||
|
typeof raw.host === "string" && raw.host.trim()
|
||||||
|
? raw.host.trim()
|
||||||
|
: "127.0.0.1";
|
||||||
return {
|
return {
|
||||||
enabled: typeof raw.enabled === "boolean" ? raw.enabled : true,
|
enabled: typeof raw.enabled === "boolean" ? raw.enabled : true,
|
||||||
host:
|
host:
|
||||||
typeof raw.host === "string" && raw.host.trim()
|
rawHost === "127.0.0.1" && hasExternalAllowedHost(allowedHosts)
|
||||||
? raw.host.trim()
|
? "0.0.0.0"
|
||||||
: "127.0.0.1",
|
: rawHost,
|
||||||
allowedHosts:
|
allowedHosts,
|
||||||
typeof raw.allowedHosts === "string" && raw.allowedHosts.trim()
|
|
||||||
? raw.allowedHosts.trim()
|
|
||||||
: "localhost, 127.0.0.1",
|
|
||||||
port:
|
port:
|
||||||
typeof raw.port === "number" && raw.port >= 1024 && raw.port <= 65535
|
typeof raw.port === "number" && raw.port >= 1024 && raw.port <= 65535
|
||||||
? raw.port
|
? raw.port
|
||||||
|
|||||||
Reference in New Issue
Block a user