From 67a0b8e3142d06292ed8ae419ea7be44909f41f8 Mon Sep 17 00:00:00 2001 From: Brice Schaffner Date: Thu, 12 Sep 2024 15:25:54 +0200 Subject: [PATCH] PB-932: Avoid UTF-8 truncation in logging The request body is in utf-8 which needs either 1 byte or 2 bytes per character depending on the character, so we need to decode first before truncating otherwise we might truncate in the middle of a utf-8 character and it will break the decode. --- app/middleware/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/middleware/logging.py b/app/middleware/logging.py index 5fa71038..6b2d7c3e 100644 --- a/app/middleware/logging.py +++ b/app/middleware/logging.py @@ -28,7 +28,7 @@ def __call__(self, request): ] and request.content_type == "application/json" and not request.path.startswith( '/api/stac/admin' ): - extra["request.payload"] = request.body[:200].decode() + extra["request.payload"] = request.body.decode()[:200] logger.debug( "Request %s %s?%s",