Most HAProxy exposures do not come from the proxy engine but from four things operators control directly: the Runtime API socket, the statistics page, TLS settings toward clients and servers, and how forwarding headers are trusted. HAProxy is one of the most widely deployed load balancers and reverse proxies, so a socket left on a TCP port or a stats page with administrative actions enabled can hand an attacker control of traffic for every application behind it.
This guide walks through the documented controls for each area, using the HAProxy 3.2 configuration and management manuals and HAProxy Technologies' configuration tutorials. It is written for platform and security engineers running HAProxy on hosts or containers. For general load balancer design, including management planes and DDoS resilience, see the Load Balancer Security Guide; this page stays specific to HAProxy.
This is an independent guide from NHI Mgmt Group, based on HAProxy's public documentation as of November 2026. It is not sponsored or reviewed by HAProxy Technologies. Product features change, so confirm settings against HAProxy's current documentation for your version.
Key takeaways
- The Runtime API (stats socket) is not enabled by default. When you enable it, use a Unix socket with
mode 600, grant only the level each consumer needs, and never expose it on a TCP port reachable by untrusted networks. - Start HAProxy as root so it can set limits and
chroot, then drop to a dedicateduserandgroup. Keep the chroot directory empty and not writable. ssl-server-verifydefaults torequired. Never set it, or a server line, toverify noneto make a backend connection work; supply a proper CA file instead.- Set
ssl-default-bind-optionswith a modernssl-min-ver; the manual's own example ofTLSv1.0is illustrative, not a recommendation. - The stats page needs authentication, network restriction and, if
stats adminis used at all, an ACL rather thanif TRUE. - Remove client-supplied forwarding headers at the edge before adding your own, so backends cannot be fooled about the client address.
Process isolation: chroot, user and privileges
HAProxy is designed to isolate itself into a chroot jail during startup. The chroot global keyword changes into the jail directory and calls chroot() before dropping privileges, and works only when HAProxy is started with superuser privileges. The manual is explicit that the jail directory must be both empty and non-writable to anyone. A writable jail lets a compromised process plant files it can later use.
The management manual gives the general advice never to start HAProxy as an unprivileged user for production, partly because starting as root lets HAProxy raise its own file descriptor limits. The safe pattern is therefore:
- Start as root via the service manager.
- Set
chrootto an empty, root owned directory such as/var/lib/haproxy. - Set
userandgroupto a dedicated account with no login shell and no other purpose. - Keep certificates, keys and configuration readable by root and that group only.
Because the chrooted process cannot see the filesystem, it cannot reload configuration in place; reloads are handled by the master process or service manager. Plan certificate updates through the Runtime API or a reload, not by expecting HAProxy to reread files.
Two global options weaken isolation and should stay off unless you have a documented need:
insecure-fork-wanted. By default HAProxy tries hard to prevent thread and process creation after startup. The manual warns that disabling this protection is a bad idea because it makes vulnerabilities easier to exploit. It is sometimes enabled for external health check scripts or Lua code that spawns processes; prefer alternatives.expose-experimental-directives. Required before experimental directives can be used; the manual notes the features it unlocks are not guaranteed to work well. Do not enable it on production edges.
Set hard-stop-after so old processes left behind by reloads do not hold connections, and old configuration, indefinitely. The manual's example is 30 seconds; choose a value that fits your longest legitimate connections.
Securing the Runtime API (stats socket)
The Runtime API lets operators and automation inspect and change HAProxy at run time over a socket. The management manual states that the stats socket is not enabled by default, and gives the example stats socket /var/run/haproxy.sock mode 600 level admin with stats timeout 2m. It also notes that sockets can be bound to TCP addresses, and that this is never done by default because it is dangerous.
The CLI has three levels: user, operator and admin, set with the level option on the socket's bind line. A session can only lower its level, never raise it, and lowering it also drops expert and experimental modes. Commands without sufficient privilege return Permission denied. Admin level commands documented in the manual include:
disable serverandenable server, which put a server into or out of maintenance.set weightandset server, which change server weight and state.disableandenablefor health checks, agent checks and whole frontends.clear counters all, which wipes statistics that investigators may need.
The manual also documents certificate update commands such as set ssl cert, and warns that injection of files over the CLI must be done with caution. Expert and debug commands are described as extremely dangerous; misuse can crash the process.
In practice, anyone who can write to an admin level socket can take servers out of rotation, disable a frontend, redirect traffic by changing server state or weights, swap certificates and erase counters. Treat the socket as a privileged credential:
- Use Unix sockets. Bind the socket to a file path with
mode 600(or660with a dedicated group) and set the owner explicitly. Never bind an admin socket to0.0.0.0or any routable address. - Split by level. Bind separate sockets for separate consumers: a
userlevel socket for metrics collectors, anoperatorsocket for on-call tooling if needed, and anadminsocket for the deployment system only. - Know who holds access. The identities that can reach the admin socket, often a deployment agent, a configuration management run or a sidecar, are privileged non-human identities. Inventory them, scope them and review them as you would sudo rights.
- Use a short timeout. Keep
stats timeoutshort so idle sessions close. - Protect the master CLI. In master-worker mode, the master CLI controls workers and reloads; secure it with the same rules.
- Restrict file descriptor exposure.
expose-fd listenerspasses listening sockets for seamless reloads outside master-worker mode. Enable it only on a socket reachable by the reload process.
TLS toward clients
HAProxy's global TLS defaults apply to every bind line that uses ssl, which makes them the right place to enforce policy:
ssl-default-bind-optionssets default options for all bind lines. The manual's example,ssl-min-ver TLSv1.0 no-tls-tickets, shows the syntax; for a current baseline, setssl-min-ver TLSv1.2(orTLSv1.3where all clients support it), in line with NIST SP 800-52 Rev. 2.ssl-default-bind-cipherssets the cipher list for TLS 1.2 and earlier. The manual points to Mozilla's server side TLS guidance for suitable lists. Restrict to AEAD suites with forward secrecy.ssl-default-bind-ciphersuitessets TLS 1.3 suites. The manual notes the OpenSSL default isTLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256and that putting TLS 1.2 suites here is undocumented and not recommended.- DH parameters. Without custom parameters, DHE ciphers are not used unless
tune.ssl.default-dh-paramis set. The manual warns that 1024-bit DH parameters should not be considered secure and advises at least 2048-bit parameters viassl-dh-param-file. Simpler still: prefer ECDHE suites and leave DHE out. - Session tickets.
no-tls-ticketsdisables stateless session tickets. If you keep tickets, rotate the ticket keys, since a stolen key can decrypt recorded sessions that resumed with it.
Manage certificate lifetimes centrally and alert well before expiry. Public TLS certificate lifetimes are shrinking, and the Certificate Expiry Outages and 47-Day TLS Certificates Guide covers the automation needed. HAProxy's Runtime API certificate commands allow updates without reload, which is another reason to restrict who can reach the admin socket.
TLS toward backend servers
Re-encrypting traffic to backends only helps if HAProxy authenticates them. The global ssl-server-verify keyword defaults to required, unless forced with the -dV command line option, and the manual warns that if it is set to none, server certificates are not verified.
The common shortcut, when a backend uses a private or self-signed certificate, is to add verify none to the server line or set ssl-server-verify none globally. That turns re-encryption into encryption without authentication and allows anyone on the path to impersonate the backend. Instead:
- Issue backend certificates from an internal CA and reference it with
ca-fileon the server lines or inssl-default-server-options. - Check the backend name as well as the chain, using the server's SNI or an explicit expected name.
- Where backends require client authentication, give HAProxy a dedicated client certificate per environment; it is a workload identity, so rotate it and restrict its key file. The mTLS Guide covers issuance and rotation.
- Search configuration repositories for
verify noneand-dVin service files, and treat any hit as a finding.
Locking down the statistics page
The statistics dashboard is enabled per frontend. HAProxy Technologies' tutorial shows a frontend that binds :8404, uses stats enable, stats refresh 10s and stats uri /stats. Out of the box, that is an unauthenticated HTTP page listing every frontend, backend and server with health and traffic data, which is valuable reconnaissance for an attacker.
The tutorial documents the controls to add:
stats auth <username>:<password>enforces basic authentication. Give each audience its own credentials, keep them out of shared configuration where possible and rotate them like any other shared secret.stats admin if <condition>lets users perform administrative actions, such as putting servers into maintenance, from the page. The tutorial notes thatif TRUEgives all users access; use an ACL that checks the source address instead, or leave admin actions off and use the Runtime API.stats scopelimits which frontends, backends and listen sections are shown; users cannot change the state of hidden servers.- Deny everything else. The tutorial's pattern routes stats paths by ACL and returns
http-request deny deny_status 404for anything unmatched.
NHI Mgmt Group also recommends binding the stats frontend to a management address or loopback rather than all interfaces, serving it over TLS when credentials cross a network, and using the Prometheus exporter or a user level socket for metrics collection so monitoring systems never need dashboard credentials.
Header controls and client address trust
Backends often log, rate limit or authorise based on the client address that HAProxy passes in X-Forwarded-For. HAProxy Technologies' client IP preservation tutorial documents option forwardfor, which stores the client address in that header and can be set in defaults, frontend, listen or backend sections. Its except argument disables the header for a given address or range, and if-none adds the header only when it is not already present.
That last option matters for security. With if-none, a header supplied by the client passes through untouched, so any client can claim any address. At the internet edge:
- Do not use
if-noneon frontends that receive traffic directly from clients. - Delete client-supplied forwarding headers before adding your own, for example with an
http-request del-header X-Forwarded-Forrule ahead ofoption forwardfor, and do the same forForwarded,X-Real-IPand any custom identity headers backends trust. - If HAProxy sits behind another trusted balancer or CDN, accept forwarded addresses only from that tier's address ranges, using an ACL on the source address.
- Configure backends to trust forwarding headers only from HAProxy's addresses.
Apply the same discipline to any header that conveys identity, such as a header carrying an authenticated user or client certificate details. Strip it on the way in and set it only after HAProxy has performed the check. On responses, consider removing headers that reveal backend software versions. Confirm exact directive syntax for header rules against the configuration manual for your version.
Limits, timeouts and logging
Resource limits protect both HAProxy and the servers behind it. Set global and per frontend maxconn to values your hosts can sustain, set maxconn on server lines so backends are not overwhelmed, and define client, server, connect and HTTP request timeouts in defaults so slow clients cannot hold connections open. Use stick tables to rate limit by source where abuse is expected, and keep volumetric protection upstream; the DDoS Protection Guide covers those layers.
For logging, send HAProxy logs to a central collector with the client address, the forwarded address, the frontend, backend and server, the TLS version and cipher, timers and termination state. Alert on:
- Runtime API commands that change server state, weights or certificates, if your tooling logs them.
- New listeners or stats frontends appearing in configuration.
- Configuration changes that add
verify none,stats admin if TRUEor a TCP bound stats socket. - Sudden changes in TLS versions or cipher use, which may signal downgrade attempts or misconfigured clients.
Track HAProxy security releases for your branch and patch internet-facing instances promptly. Exposed load balancers are a common entry point and map to MITRE ATT&CK T1190, Exploit Public-Facing Application.
Common failure patterns
- Runtime API on TCP. An admin level socket bound to a routable address, often added for remote automation, lets anyone who reaches it control traffic.
- One admin socket for everything. Metrics collectors and dashboards share the admin socket, so a compromised monitoring agent can change server state.
- Open stats page. The dashboard is published on all interfaces with no authentication.
stats admin if TRUE. Every authenticated user, or every visitor, can put servers into maintenance.verify noneto backends. Re-encryption without authentication, usually added to get past a certificate error.- Weak TLS floor. Copied examples leave
ssl-min-ver TLSv1.0or broad cipher lists in place. - Trusting client headers.
option forwardfor if-noneat the edge lets clients choose their logged and rate limited address. - Weakened isolation. Writable chroot directories, HAProxy running as root after startup, or
insecure-fork-wantedenabled for convenience.
Practitioner checklist
- Run HAProxy with
chrootto an empty, non-writable directory and drop to a dedicateduserandgroup. - Keep
insecure-fork-wantedandexpose-experimental-directivesdisabled; sethard-stop-after. - Bind the Runtime API to Unix sockets only, with
mode 600or a dedicated group, and separate sockets per level. - Inventory every identity that can reach an admin socket and review it like privileged access.
- Set
ssl-default-bind-optionswithssl-min-ver TLSv1.2or higher, restrict ciphers and avoid 1024-bit DH. - Keep
ssl-server-verify required, provideca-filefor backends and remove everyverify none. - Protect the stats page with
stats auth, a management only bind address,stats scopeand nostats admin if TRUE. - Strip client-supplied forwarding and identity headers at the edge before setting your own.
- Set
maxconnand timeouts globally, per frontend and per server. - Centralise logs, alert on risky configuration changes and patch on each security release.
Standards and references
- HAProxy: Configuration Manual 3.2
- HAProxy: Management Guide 3.2 (Runtime API)
- HAProxy Technologies: Statistics dashboard tutorial
- HAProxy Technologies: Add X-Forwarded-For header
- NIST: SP 800-52 Rev. 2, Guidelines for the Selection, Configuration, and Use of TLS Implementations
- IETF: RFC 8446 The Transport Layer Security (TLS) Protocol Version 1.3
- MITRE ATT&CK: Exploit Public-Facing Application
- NIST: SP 800-53 Rev. 5 (SC-7 Boundary Protection, SC-8 Transmission Confidentiality and Integrity)
Related NHI Mgmt Group resources: Load Balancer Security Guide · Proxies and Forward vs Reverse Proxy Security Guide · mTLS Guide · DDoS Protection Guide