• Web server: behind a reverse proxy, ip.can and the request rate limite

    From Rob Swindell@1:103/705 to GitLab issue in main/sbbs on Saturday, November 21, 2026 18:01:23
    open https://gitlab.synchro.net/main/sbbs/-/work_items/1389

    Behind a reverse proxy (`RemoteIPHeader` set in `[Web]`), the web server's address-based filters act on the wrong address, or not at all, because they run before `parse_headers()` replaces `session->host_ip` with the address from the header.

    ## `ip.can` entries for forwarded clients are never enforced

    `ip.can` is checked once per connection, in `http_session_thread()` (`websrvr.cpp`, `ip_can.listed(session.host_ip, ...)`), against the connecting address: the proxy's. `ip-silent.can` is checked at accept, also against the proxy. An `ip.can` entry for a forwarded client's address therefore never refuses anything, whether it was:

    - added by hand,
    - written by the request rate limiter's auto-filter (`RateLimitFilterThreshold`), or
    - written by the request-header blocking `FilterThreshold` (#1375), which runs after `parse_headers()` and so filters the forwarded address, as intended.

    The entry is written and logged (`!BLOCKING IP ADDRESS ... in ip.can`), so it looks effective, but the client's later requests come through the proxy and are not refused. (#1375's header rules still block each matching request, but a filtered client is otherwise unaffected.)

    ## The request rate limiter uses the address from before the header

    `get_req()` runs the `host_exempt` check and the request rate limiter before `parse_headers()` has applied `RemoteIPHeader`. On the first request of a connection that is the proxy's address, so:

    - with the proxy listed in `ipfilter_exempt.cfg` (the stock file exempts loopback and private ranges), the first request of every connection skips the rate limiter;
    - with the proxy not exempt, every client's first requests count against the proxy's own bucket, and the auto-filter can write the **proxy's** address into `ip.can`, shutting out all visitors.

    On later requests of a kept-alive connection, `host_ip` still holds the previous request's forwarded address (see the keep-alive item in #1283), so the limiter uses that.

    ## Proposal

    After `parse_headers()` has applied `RemoteIPHeader` and the address changed, check the new address before handling the request:

    - `ip.can` / `host.can` / the login-attempt ban: refuse with `403 Forbidden` (or close without a response for `ip-silent.can`), logging `!CLIENT BLOCKED` as the connection-time check does. `ipfilter_exempt.cfg` applies to the new address.
    - Move the request rate limiter (and its `host_exempt` check) to the same point, so it counts the forwarded address from the first request on.

    ## Related

    - #1283 (honor `RemoteIPHeader` only from trusted proxy addresses) should land first or together: enforcing `ip.can` on the header's address is only meaningful once a directly connecting client can no longer choose that address.
    - #280 (configurable trusted reverse proxy).

    -- *Authored by Claude (Claude Code), on behalf of @rswindell*
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell@1:103/705 to GitLab issue in main/sbbs on Saturday, November 21, 2026 19:18:31
    close https://gitlab.synchro.net/main/sbbs/-/work_items/1389
    2026-11-21 19:18:28 -0800
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)