Search code examples
http-headersconditional-statementshaproxy

Configuring HAProxy to reject/deny requests containing multiple HTTP headers of the same name


I'd like to express the HAProxy condition

the request contains more than one Transfer-Encoding headers

so I can deny or reject such requests. I've scanned through the HAProxy documentation, but I couldn't find how to express that condition. Is it even possible?


Solution

  • The req.hdr_cnt or req.fhdr_cnt fetches should be usable for your purpose. They return the number of occurrences of a particular request header. They differ in that req.hdr_cnt counts comma-separated parts of a header value as distinct headers.

    acl too_many_headers req.fhdr_cnt(transfer-encoding) gt 1