https://gitlab.synchro.net/main/sbbs/-/commit/c5a3b3a971e567e7b19eee9d
Modified Files:
ctrl/sbbs.ini docs/v322_new.md src/sbbs3/sbbs_ini.c src/sbbs3/scfg/scfgindex.h scfgsrvr.c src/sbbs3/userdat.c userdat.h websrvr.cpp websrvr.h
Log Message:
Web Server: trusted reverse proxies, and filter the forwarded address
RemoteIPHeader (7712fdfa3e, receptors-12-suggestion, 2025-11-11) lets a
site behind a reverse proxy or CDN, such as Cloudflare
(CF-Connecting-IP), see each client's own address. Two problems
remained.
Any client could set that header (#1283). The new [Web]
RemoteIPHeaderTrust setting lists the proxy addresses or CIDR ranges (comma-separated, the .can/.cfg pattern syntax) whose RemoteIPHeader is believed; the header from any other connection is ignored. Left blank,
any client's header is believed, as before, so an upgraded proxied site
keeps working, and a warning is logged at startup. A comma-separated
value, or the same header given more than once (X-Forwarded-For), yields
its right-most address that is not a trusted proxy, the address the
outermost trusted proxy received the request from; before, a list was
rejected as invalid.
The address-based checks ran before the header was applied (#1389). The
request rate limiter and its exemption check ran in get_req(), before parse_headers(), so on a connection's first request they acted on the
proxy: with the proxy exempt (the stock ipfilter_exempt.cfg exempts
loopback and private ranges) those requests skipped the limiter, and
with it not exempt every client counted against, and could get filtered,
the proxy's own address. ip.can was checked only when a connection was accepted, against the proxy, so an ip.can entry for a forwarded client, including one the rate limiter or web_block.ini wrote, never refused it.
Now, after parse_headers(), each request is checked against ipfilter_exempt.cfg, and a forwarded address against ip-silent.can
(connection dropped) and ip.can (403), then web_block.ini, then the rate limiter. Internal redirects are not counted as requests. A forwarded
client's checks and filter entries no longer use the proxy's hostname.
Failed web logins were counted, and temporary bans checked, against the connecting address: behind an exempt proxy no client was ever banned for guessing passwords, and behind one that was not exempt, one client's
failures banned everyone. They are now counted against the request's
client, and a forwarded address under a temporary ban is refused (403); loginBannedAddr() is loginBanned() for an address rather than a socket.
Each request on a kept-alive connection now starts from the connection's
own address, so a request without the header no longer keeps the
address an earlier request forwarded.
In the access log's CustomLogFormat, %a is now the request's client (the forwarded address), as Apache's is with a trusted proxy, and the new
%{c}a is the connecting address, as in Apache. %h was already the
forwarded address.
SCFG: Web Server > Reverse Proxy holds Client IP Header (RemoteIPHeader,
until now set only in sbbs.ini) and Trusted Proxies.
web_startup_t gained a member, so sbbsctrl.exe must be rebuilt.
Tested on Linux against an isolated test server with RemoteIPHeader = X-Forwarded-For: the startup warning with no trust list; a header from a
peer not in the list ignored; with 127.0.0.0/8 trusted, the right-most untrusted address of a list and of two header lines; an invalid value
ignored; a kept-alive second request without the header logged under the connection's address; forwarded addresses in ip.can (403) and
ip-silent.can (dropped); the rate limiter counting a forwarded client
from its first request (429 on the 4th of 3 allowed) while another
client and the exempt proxy itself were not limited; web_block.ini
blocking and filtering a forwarded client; three wrong passwords from a forwarded client temporarily banning it (403 with the right password)
while another forwarded client and a direct one logged in; %a, %{c}a and
%h in a custom log format. SCFG built, not exercised.
Fixes #1283
Fixes #1389
Fixes #280
Co-Authored-By: Claude Opus 5.5 <
noreply@anthropic.com>
--- SBBSecho 3.38-Linux
* Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)