Hi,

I have a beginner question please: in 2.6 and 2.8 I am using this custom 
log-format to log the body of requests:

global
...
log 127.0.0.1 len 32000 local0
tune.http.logurilen 20480
...
defaults
...
log-format "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc 
%ac/%fc/%bc/%sc/%rc %sq/%bq %{+Q}r 
%[fc_err]/%[ssl_fc_err,hex]/%[ssl_c_err]/\%[ssl_c_ca_err]/%[ssl_fc_is_resumed] 
%[ssl_fc_sni]/%sslv/%sslc Payload: %{+Q}[capture.req.hdr(0)]"
...

frontend https-in
bind *:443 ssl crt /ssl/ alpn h2,http/1.1 shards by-thread
bind [::]:443 ssl crt /ssl/ alpn h2,http/1.1 shards by-thread

# Here I capture the body payload of max 10k characters
declare capture request len 10000
http-request capture req.body id 0
mode http....

and if I send a json as payload with curl like this:
curl -X POST http://domain.com:80/api -H "Content-Type: application/json" -d 
'{"city": "SomeCity"}'

I get:
<134>1 2025-03-27T23:40:59+00:00 localhost haproxy 800275 - - ip-here:43116 
[27/Mar/2025:23:40:59.018] https-in test/server1 0/0/0/6/6 200 160 - - ---- 
1/1/0/0/0 0/0 "POST /api HTTP/1.1" 0/-/-/\-/0 -/-/- Payload: "{"city": 
"SomeCity"}"
this means the json was received correctly: Payload: "{"city": "SomeCity"}"

But if my json has a new line inside it like this:
curl -X POST http://domain.com:80/api -H "Content-Type: application/json" -d 
"$(printf '{"city":\n"SomeCity"}')"

I get:
#012 instead of new line:
<134>1 2025-03-27T23:44:34+00:00 localhost haproxy 800275 - - ip-here:40356 
[27/Mar/2025:23:44:34.056] https-in test/server1 0/0/0/4/4 200 159 - - ---- 
1/1/0/0/0 0/0 "POST /api HTTP/1.1" 0/-/-/\-/0 -/-/- Payload: "{"city": 
#012"SomeCity"}"
and my Payload: "{"city": #012"SomeCity"}" contains #012 numbers now which the 
backend apps cannot make too much sense of (I don't have control over backend 
apps).

and sometimes #012#015 which corresponds to the platform that sent the message: 
LF+CR or just LF.

Is there a way to unescape these numbers to characters in Haproxy alone? In my 
particular case I don't have control over the backend apps so I need to 
'sanitize' the json before leaving haproxy/before logged to disk/sent to 
rsyslogd.

Thank you,

Dragos

Ps: to log via rsyslogd such big messages (10k characters or more) on Ubuntu 
like systems, you also need this in /etc/rsyslog.d/50-default.conf
$MaxMessageSize 32k
besides the rsyslog haproxy config, otherwise it will truncate the logs to a 
default lower value.

Reply via email to