From 3e4ed0c299f110f0bf951e1f1b4a9fbacbe9d425 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Tue, 4 Aug 2026 10:59:35 -0600 Subject: [PATCH] Merge pull request #4966 from Dokploy/fix/requests-hostname-filter-crash fix(requests): guard RequestHost before filtering to avoid crash on malformed logs (cherry picked from commit a0162ab5669badc9a8eb1aa45b44812a2bfda480) --- .../dokploy/__test__/requests/request.test.ts | 22 +++++++++++++++++++ packages/server/src/utils/access-log/utils.ts | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/dokploy/__test__/requests/request.test.ts b/apps/dokploy/__test__/requests/request.test.ts index 3f58ac439..844458fd2 100644 --- a/apps/dokploy/__test__/requests/request.test.ts +++ b/apps/dokploy/__test__/requests/request.test.ts @@ -55,6 +55,28 @@ describe("processLogs", () => { expect(result.data).toHaveLength(2); }); + it("should not throw when filtering by hostname and an entry has no RequestHost", () => { + const entryWithoutRequestHost = sampleLogEntry.replace( + /"RequestHost":"[^"]*",/, + "", + ); + + const mixedEntries = `${sampleLogEntry}\n${entryWithoutRequestHost}`; + + expect(() => + parseRawConfig(mixedEntries, undefined, undefined, "traefik.me"), + ).not.toThrow(); + + const result = parseRawConfig( + mixedEntries, + undefined, + undefined, + "traefik.me", + ); + expect(result.totalCount).toBe(1); + expect(result.data[0]?.RequestHost).toBe("s222-umami-c381af.traefik.me"); + }); + it("should filter out Dokploy dashboard requests", () => { const dokployDashboardEntry = `{"ClientAddr":"172.71.187.131:9485","ClientHost":"172.71.187.131","ClientPort":"9485","ClientUsername":"-","DownstreamContentSize":14550,"DownstreamStatus":200,"Duration":57681682,"OriginContentSize":14550,"OriginDuration":57612242,"OriginStatus":200,"Overhead":69440,"RequestAddr":"hostinger.dokploy.com","RequestContentSize":0,"RequestCount":20142,"RequestHost":"hostinger.dokploy.com","RequestMethod":"GET","RequestPath":"/_next/data/cb_zzI4Rp9G7Q7djrFKh0/en/dashboard/traefik.json","RequestPort":"-","RequestProtocol":"HTTP/2.0","RequestScheme":"https","RetryAttempts":0,"RouterName":"dokploy-router-app-secure@file","ServiceAddr":"dokploy:3000","ServiceName":"dokploy-service-app@file","ServiceURL":"http://dokploy:3000","StartLocal":"2025-12-10T05:10:41.957755949Z","StartUTC":"2025-12-10T05:10:41.957755949Z","TLSCipher":"TLS_AES_128_GCM_SHA256","TLSVersion":"1.3","entryPointName":"websecure","level":"info","msg":"","time":"2025-12-10T05:10:42Z"}`; diff --git a/packages/server/src/utils/access-log/utils.ts b/packages/server/src/utils/access-log/utils.ts index 9b472ee27..ddaef3ec4 100644 --- a/packages/server/src/utils/access-log/utils.ts +++ b/packages/server/src/utils/access-log/utils.ts @@ -120,7 +120,7 @@ export function parseRawConfig( if (search) { parsedLogs = parsedLogs.filter((log) => - log.RequestHost.toLowerCase().includes(search.toLowerCase()), + (log.RequestHost ?? "").toLowerCase().includes(search.toLowerCase()), ); }