Skip to content

Build your personal knowledge base with Trilium Notes

fix(desktop): read the Host header via req.get() to satisfy the type augmentation (#10589)

Elian Dorane890201f0043
diff --git a/apps/server/src/services/desktop_network_gate.spec.ts b/apps/server/src/services/desktop_network_gate.spec.ts
index 75c5d696b9..fa11f0bc50 100644
--- a/apps/server/src/services/desktop_network_gate.spec.ts
+++ b/apps/server/src/services/desktop_network_gate.spec.ts
@@ -16,6 +16,12 @@ function makeRes() {
return res as unknown as Response & { status: ReturnType<typeof vi.fn>; send: ReturnType<typeof vi.fn> };
}
+// A plain-object stand-in for an external (unmarked) request: the middleware reads the
+// path and the Host header via req.get("host").
+function makeReq(path: string, host: string | undefined): Request {
+ return { path, get: (name: string) => (name.toLowerCase() === "host" ? host : undefined) } as unknown as Request;
+}
+
describe("isLocalIntegrationPath", () => {
it("matches the MCP and clipper endpoints (and only those)", () => {
expect(isLocalIntegrationPath("/mcp")).toBe(true);
@@ -89,7 +95,7 @@ describe("desktopNetworkAccessGate (desktop build, network access off)", () => {
const res = makeRes();
const next = vi.fn() as unknown as NextFunction;
// A plain object carries no internal-electron marker → treated as external/TCP.
- desktopNetworkAccessGate({ path: "/", headers: { host: "localhost:37742" } } as unknown as Request, res, next);
+ desktopNetworkAccessGate(makeReq("/", "localhost:37742"), res, next);
expect(res.status).toHaveBeenCalledWith(403);
expect(next).not.toHaveBeenCalled();
@@ -98,7 +104,7 @@ describe("desktopNetworkAccessGate (desktop build, network access off)", () => {
it("passes localhost-integration requests through to the next handler", () => {
const res = makeRes();
const next = vi.fn() as unknown as NextFunction;
- desktopNetworkAccessGate({ path: "/api/clipper/handshake", headers: { host: "localhost:37742" } } as unknown as Request, res, next);
+ desktopNetworkAccessGate(makeReq("/api/clipper/handshake", "localhost:37742"), res, next);
expect(next).toHaveBeenCalled();
expect(res.status).not.toHaveBeenCalled();
diff --git a/apps/server/src/services/desktop_network_gate.ts b/apps/server/src/services/desktop_network_gate.ts
index 0a2f38b343..9deaf668c4 100644
--- a/apps/server/src/services/desktop_network_gate.ts
+++ b/apps/server/src/services/desktop_network_gate.ts
@@ -85,7 +85,7 @@ export function desktopNetworkAccessGate(req: Request, res: Response, next: Next
allowLanAccess: config.Security?.allowLanAccess === true,
isInternal: isInternalElectronRequest(req),
path: req.path,
- host: req.headers.host
+ host: req.get("host")
});
if (blocked) {