Skip to content

Commit 314a31d

Browse files
committed
fix(requests): guard RequestHost before filtering to avoid crash on malformed logs
1 parent 46c87a2 commit 314a31d

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎apps/dokploy/__test__/requests/request.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ describe("processLogs", () => {
5555
expect(result.data).toHaveLength(2);
5656
});
5757

58+
it("should not throw when filtering by hostname and an entry has no RequestHost", () => {
59+
const entryWithoutRequestHost = sampleLogEntry.replace(
60+
/"RequestHost":"[^"]*",/,
61+
"",
62+
);
63+
64+
const mixedEntries = `${sampleLogEntry}\n${entryWithoutRequestHost}`;
65+
66+
expect(() =>
67+
parseRawConfig(mixedEntries, undefined, undefined, "traefik.me"),
68+
).not.toThrow();
69+
70+
const result = parseRawConfig(
71+
mixedEntries,
72+
undefined,
73+
undefined,
74+
"traefik.me",
75+
);
76+
expect(result.totalCount).toBe(1);
77+
expect(result.data[0]?.RequestHost).toBe("s222-umami-c381af.traefik.me");
78+
});
79+
5880
it("should filter out Dokploy dashboard requests", () => {
5981
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"}`;
6082

‎packages/server/src/utils/access-log/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function parseRawConfig(
120120

121121
if (search) {
122122
parsedLogs = parsedLogs.filter((log) =>
123-
log.RequestHost.toLowerCase().includes(search.toLowerCase()),
123+
(log.RequestHost ?? "").toLowerCase().includes(search.toLowerCase()),
124124
);
125125
}
126126

0 commit comments

Comments
 (0)