diff --git a/packages/server/logging/expressLogging.ts b/packages/server/logging/expressLogging.ts index 0c3b40fe06..3ed0ca38e5 100644 --- a/packages/server/logging/expressLogging.ts +++ b/packages/server/logging/expressLogging.ts @@ -44,7 +44,8 @@ export const LoggingExpressMiddleware = HttpLogger({ customSuccessObject(req, res, val: Record) { const isCompleted = !req.readableAborted && res.writableEnded const requestStatus = isCompleted ? 'completed' : 'aborted' - const requestPath = req.url?.split('?')[0] || 'unknown' + const requestPath = + (get(req, 'originalUrl') || get(req, 'url') || '').split('?')[0] || 'unknown' const country = req.headers['cf-ipcountry'] as Optional return { @@ -60,7 +61,8 @@ export const LoggingExpressMiddleware = HttpLogger({ }, customErrorObject(req, res, err, val: Record) { const requestStatus = 'failed' - const requestPath = req.url?.split('?')[0] || 'unknown' + const requestPath = + (get(req, 'originalUrl') || get(req, 'url') || '').split('?')[0] || 'unknown' const country = req.headers['cf-ipcountry'] as Optional return { @@ -79,7 +81,7 @@ export const LoggingExpressMiddleware = HttpLogger({ return { id: req.raw.id, method: req.raw.method, - path: req.raw.url?.split('?')[0], // Remove query params which might be sensitive + path: (get(req.raw, 'originalUrl') || get(req.raw, 'url') || '').split('?')[0], // Allowlist useful headers headers: Object.fromEntries( Object.entries(req.raw.headers).filter(