set-proxy-v2-tlv-fmt silently truncates binary TLV values at first null byte (0x00)
Detailed Description of the Problem
When forwarding a PPv2 TLV containing embedded null bytes using set-proxy-v2-tlv-fmt(0xE1) %[fc_pp_tlv(0xE1)], the outbound TLV value is silently truncated at the first 0x00 byte. The bytes after the first null are lost.
Expected Behavior
set-proxy-v2-tlv-fmt should forward the exact binary value received by fc_pp_tlv, preserving all bytes including nulls. The PROXY Protocol v2 spec defines TLVs as length-delimited binary, not null-terminated strings.
Steps to Reproduce the Behavior
- Configure HAProxy to forward a binary PPv2 TLV:
frontend fe
bind *:8080 accept-proxy
default_backend be
backend be
server srv <backend>:443 ssl verify none send-proxy-v2 \
set-proxy-v2-tlv-fmt(0xE1) %[fc_pp_tlv(0xE1)]- Send a PPv2 connection with a custom TLV type 0xE1 containing 31 bytes of binary data that includes null bytes (e.g. at byte offset 19):
Inbound TLV:
e1 00 1f 20 30 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx 00 00 00 xx xx xx xx xx 00 00 00 01
^--- 31 bytes, nulls at offset 19-21 and 29-30 ---^Capture the outbound PPv2 header (tcpdump on the backend port).
Observe the outbound TLV is truncated:
Outbound TLV:
e1 00 13 20 30 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
^--- only 19 bytes, stopped at first 0x00 ---^Do you have any idea what may have caused this?
The receive and emit paths are both binary-safe:
smp_fetch_fc_pp_tlv(src/connection.c) stores the value with explicit.datalength viamemcpymake_tlv(src/connection.c) writes with explicit length viamemcpy
The truncation occurs in the format rendering path between them:
set-proxy-v2-tlv-fmtbuilds the value viasess_build_loglinefc_pp_tlvis registered asSMP_T_STR(src/connection.c, fetch table)- For
SMP_T_STRsamples,_lf_text_len(src/log.c) usesstrlcpy2()which stops at the first0x00
The binary-safe path (lf_encode_chunk) exists in build_logline but is only reached when the sample type is SMP_T_BIN and LOG_OPT_BIN is set, neither of which applies to fc_pp_tlv by default.
Do you have an idea how to solve the issue?
Changing fc_pp_tlv from SMP_T_STR to SMP_T_BIN globally would fix this but may break existing users who rely on string behavior (e.g. string comparisons in ACLs, log-format rendering of text TLVs like PP2_SUBTYPE_AWS_VPCE_ID).
Possible backward-compatible approaches:
- A new fetch variant (e.g.
fc_pp_tlv_bin()) that returnsSMP_T_BIN - An option or converter that forces binary handling in
set-proxy-v2-tlv-fmt - Making
set-proxy-v2-tlv-fmtuse length-based copy instead ofstrlcpy2regardless of sample type, since TLV values are always binary by spec
Defer to the HAProxy team on the best approach.
What is your configuration?
global
log stdout format raw local0 info
defaults
mode http
timeout connect 5s
timeout client 30s
timeout server 30s
frontend fe
bind *:8080 accept-proxy
default_backend be
backend be
server srv <backend-ip>:443 ssl verify none send-proxy-v2 \
set-proxy-v2-tlv-fmt(0xE1) %[fc_pp_tlv(0xE1)]Output of haproxy -vv
haproxy -vv
HAProxy version 3.0.23-44b4517fc-2.amzn2023.0.1 2026/05/11 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2029.
Known bugs: http://www.haproxy.org/bugs/bugs-3.0.23.html
Running on: Linux 6.1.177 #1 SMP PREEMPT_DYNAMIC Fri Aug 7 23:13:48 UTC 2026 x86_64
Build options :
TARGET = linux-glibc
CC = gcc
CFLAGS = -fwrapv -fvect-cost-model=very-cheap -O2 -ftree-vectorize -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -DMAX_SESS_STKCTR=12
OPTIONS = USE_OPENSSL=1 USE_LUA=1 USE_PROMEX=1 USE_PCRE2=1
DEBUG =
Feature list : -51DEGREES +ACCEPT4 +BACKTRACE -CLOSEFROM +CPU_AFFINITY +CRYPT_H -DEVICEATLAS +DL -ENGINE +EPOLL -EVPORTS +GETADDRINFO -KQUEUE -LIBATOMIC +LIBCRYPT +LINUX_CAP +LINUX_SPLICE +LINUX_TPROXY +LUA +MATH -MEMORY_PROFILING +NETFILTER +NS -OBSOLETE_LINKER +OPENSSL -OPENSSL_AWSLC -OPENSSL_WOLFSSL -OT -PCRE +PCRE2 -PCRE2_JIT -PCRE_JIT +POLL +PRCTL -PROCCTL +PROMEX -PTHREAD_EMULATION -QUIC -QUIC_OPENSSL_COMPAT +RT +SHM_OPEN +SLZ +SSL -STATIC_PCRE -STATIC_PCRE2 +SYSTEMD +TFO +THREAD +THREAD_DUMP +TPROXY -WURFL -ZLIB
Default settings :
bufsize = 16384, maxrewrite = 1024, maxpollevents = 200
Built with multi-threading support (MAX_TGROUPS=16, MAX_THREADS=256, default=2).
Built with OpenSSL version : OpenSSL 3.5.5 27 Jan 2026
Running on OpenSSL version : OpenSSL 3.5.7 9 Jun 2026
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports : TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3
OpenSSL providers loaded : default
Built with Lua version : Lua 5.4.4
Built with the Prometheus exporter as a service
Built with network namespace support.
Built with libslz for stateless compression.
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Built with PCRE2 version : 10.40 2022-04-14
PCRE2 library supports JIT : no (USE_PCRE2_JIT not set)
Encrypted password support via crypt(3): yes
Built with gcc compiler version 11.5.0 20240719 (Red Hat 11.5.0-5)
Available polling systems :
epoll : pref=300, test result OK
poll : pref=200, test result OK
select : pref=150, test result OK
Total: 3 (3 usable), will use epoll.
Available multiplexer protocols :
(protocols marked as <default> cannot be specified using 'proto' keyword)
h2 : mode=HTTP side=FE|BE mux=H2 flags=HTX|HOL_RISK|NO_UPG
h1 : mode=HTTP side=FE|BE mux=H1 flags=HTX|NO_UPG
<default> : mode=HTTP side=FE|BE mux=H1 flags=HTX
fcgi : mode=HTTP side=BE mux=FCGI flags=HTX|HOL_RISK|NO_UPG
none : mode=TCP side=FE|BE mux=PASS flags=NO_UPG
<default> : mode=TCP side=FE|BE mux=PASS flags=
Available services : prometheus-exporter
Available filters :
[BWLIM] bwlim-in
[BWLIM] bwlim-out
[CACHE] cache
[COMP] compression
[FCGI] fcgi-app
[SPOE] spoe
[TRACE] traceLast Outputs and Backtraces
Additional Information
Workaround
Base64 round-trip eliminates null bytes in the intermediate representation:
frontend fe
bind *:8080 accept-proxy
http-request set-var(sess.tlv_b64) fc_pp_tlv(0xE1),base64
backend be
server srv <backend>:443 ssl verify none send-proxy-v2 \
set-proxy-v2-tlv-fmt(0xE1) %{+bin}o%[var(sess.tlv_b64),b64dec]base64 encoding produces null-free ASCII; b64dec + %{+bin}o takes the binary-safe render path, preserving all bytes.
Source: haproxy/haproxy