1

Is it possible to somehow add arbitrary HTTP response headers to the "stats" pages in HAProxy? haproxy version 1.7.x.

Regular stats setup:

listen view
    bind *:10002
    stats enable
    stats uri /
    stats hide-version

Customizing and trying to add headers makes no difference.

This does not work, i.e. no X-Frame-Options header is added to the response:

listen view
    bind *:10002
    rspadd X-Frame-Options:\ SAMEORIGIN
    stats enable
    stats uri /
    stats hide-version

Nor does this work:

listen view
    bind *:10002
    http-response set-header X-Frame-Options SAMEORIGIN
    stats enable
    stats uri /
    stats hide-version

The exact same parameters in a "regular" listen block works like a charm.

sastorsl
  • 362
  • 2
  • 15

1 Answers1

2

stats apparently aren't processed by http code, so http-request don't work. It even has its own stats http-request with very limited functionality (https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-stats%20http-request).

Putting proxy in front of it should work:

frontend stats
        bind *:1936
        http-response set-header test test
        use_backend stats

backend stats
        server foobar 127.0.0.1:1937

listen realstats
        bind 127.0.0.1:1937
        stats enable
        stats uri /
        stats hide-version

Tested on haproxy 2.1, by it should work for 1.7 as well.

tbielaszewski
  • 441
  • 2
  • 5
  • Great answer! I tried something similar with a `frontend` and the `use_backend` directive, but using `server` was the trick the whole time! Good job! Going through `localhost` should keep the editors away as well :-) – sastorsl Sep 17 '20 at 11:39