fix(matrix): honor canonical private-network opt-in

This commit is contained in:
Gustavo Madeira Santana 2026-04-05 18:17:44 -04:00
parent c6d3ee70e2
commit 54ad458267
2 changed files with 17 additions and 2 deletions

View File

@ -718,6 +718,15 @@ describe("resolveMatrixConfig", () => {
"Matrix homeserver must use https:// unless it targets a private or loopback host",
);
});
it("accepts internal http hostnames when the private-network opt-in is explicit", async () => {
await expect(
resolveValidatedMatrixHomeserverUrl("http://localhost.localdomain:8008", {
dangerouslyAllowPrivateNetwork: true,
lookupFn: createLookupFn([{ address: "127.0.0.1", family: 4 }]),
}),
).resolves.toBe("http://localhost.localdomain:8008");
});
});
describe("resolveMatrixAuth", () => {

View File

@ -510,10 +510,16 @@ export async function resolveValidatedMatrixHomeserverUrl(
lookupFn?: LookupFn;
},
): Promise<string> {
const normalized = validateMatrixHomeserverUrl(homeserver, opts);
const allowPrivateNetwork =
typeof opts?.dangerouslyAllowPrivateNetwork === "boolean"
? opts.dangerouslyAllowPrivateNetwork
: opts?.allowPrivateNetwork;
const normalized = validateMatrixHomeserverUrl(homeserver, {
allowPrivateNetwork,
});
await assertHttpUrlTargetsPrivateNetwork(normalized, {
dangerouslyAllowPrivateNetwork: opts?.dangerouslyAllowPrivateNetwork,
allowPrivateNetwork: opts?.allowPrivateNetwork,
allowPrivateNetwork,
lookupFn: opts?.lookupFn,
errorMessage: MATRIX_HTTP_HOMESERVER_ERROR,
});