• src/sbbs3/websrvr.cpp

    From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Sat Sep 19 23:53:09 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/f9558d66d5a2d9e7df880e7c
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    websrvr: terminate the CGI read loop on a FastCGI socket failure

    fastcgi_read_wait_timeout() reported its recv(), version and session-ID failures by returning ret, which is still 0 at each of those points. Zero
    is the function's "nothing ready yet" value, so do_cgi_stuff() skipped its whole body, including the CGI_PROCESS_TERMINATED check, and polled again immediately. A socket at EOF is always readable, so nothing paced the
    retry: a backend that closed its connection left the session spinning at roughly 1.6 million iterations per second, logging at LOG_ERR on every
    one, until max_cgi_inactivity expired as much as two minutes later.

    Return CGI_PROCESS_TERMINATED from those three paths and from the two fastcgi_read_body() failures below them, so the caller tears the session
    down at once instead of treating a dead socket as a slow one.

    A php-fpm restart is enough to trigger this, which means it fires during routine package upgrades.

    #1246

    Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
    --- SBBSecho 3.37-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Wed Sep 30 20:48:07 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/651cbc9886250cb97169edf8
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web Server: shutdown() lingering session sockets when the client wait expires

    At terminate/recycle the web server thread waits up to MaxInactivity for the active clients to disconnect on their own, then gives up with "!TIMEOUT
    waiting for N active clients" and enters cleanup(), which loops until every child thread has exited. Nothing between those two steps did anything to
    the sessions that were still alive: a session thread blocked in a socket
    wait (the request-line read, the TLS close dance, the output thread's send) stayed blocked, cleanup() has no deadline, and the process never exited.
    On 2026-09-30 one idle HTTPS session on this host held the whole httpd
    service in "Waiting for 2 child threads to terminate" until systemd's 90 s
    stop timeout SIGKILLed it, 60 s of that budget having already gone to the active-client wait.

    Once the active-client wait expires, shutdown(SHUT_RDWR) the socket of
    every session still registered in current_connections. That wakes the
    blocked reader (recv() returns 0, poll() reports HUP) and lets the session thread run its normal teardown and exit; cleanup() then finishes within a second or two. Shutting down rather than closing keeps the descriptor
    owned by the session thread, which still performs the one real close, the
    same way the terminal server handles node sockets at terminate (8101584ded, symbol-19-seek, 2026-07-05).

    To make that safe, the session's current_connections node is now removed
    in close_session_socket(), immediately before the descriptor is closed,
    instead of at session-thread exit. Both the removal and the shutdown pass
    take the list lock, so the list never names a closed (and possibly reused) descriptor and a socket found in it is guaranteed to still be open.

    Validated against a scratch web server (MaxInactivity = 10s) with a plain
    HTTP client that sends a partial request line and then one byte every two seconds, so the session's inactivity timer never fires: before this change
    the server was still "Waiting for 2 child threads" 60 s after SIGTERM and
    had to be SIGKILLed; after it, the session is shut down the same second the client wait expires and the process exits 13 s after SIGTERM.

    Not covered: a connection still inside the TLS handshake is not yet in current_connections (it is added after the handshake, in client_on), so it cannot be kicked; cryptlib bounds that handshake at about 30 s. Which call
    the 2026-09-30 session thread was actually blocked in is not known (the
    SIGKILL left no core), so this is the safety net for that class of hang,
    not a fix for a specific blocking call.

    Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Wed Sep 30 20:48:07 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/a45592ec5bae024adf511679
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web Server: bound the shutdown wait for child threads, re-kick while waiting

    cleanup() looped on thread_count with no deadline. The previous commit
    (the shutdown() kick of listed session sockets) ends that loop quickly
    whenever the lingering thread is blocked on its client socket, but a thread blocked anywhere else - a script in a native call, a CGI pipe, a mutex -
    is out of its reach, and one such thread still held the whole server (and
    under systemd, the stop timeout) hostage until SIGKILL.

    Give up after TIMEOUT_THREAD_WAIT (60 s), the same bound the terminal, mail
    and FTP servers put on their own thread waits, logging "!TIMEOUT waiting
    for N child thread(s) to terminate" at error level. While waiting, re-run shutdown_sessions() every 5 s: a connection that completes its TLS
    handshake after the first pass is only then registered in
    current_connections, and each pass also logs what is still connected. A
    thread still running at the deadline is abandoned; the counter is left undestroyed (with a "!!!! Terminating with N child thread(s) still running" warning, as active_clients already does) so its eventual thread_down() is harmless. thread_count is initialized once per server start, not per
    recycle, so a thread abandoned by a recycle still decrements the right
    counter when it finally exits.

    Validated against a scratch web server (MaxInactivity = 10s) with an SSJS
    page that calls mswait(120000): before, the kick fired and the server was
    still "Waiting for 2 child threads" when SIGKILLed at 100 s; after, it logs
    the timeout and exits cleanly 73 s after SIGTERM (10 s client wait + 60 s thread wait), exit code 0, no core. The slow-client scenario from the
    previous commit still exits in 13 s.

    Budget note for systemd hosts: the worst case is now MaxInactivity plus
    60 s. With the default TimeoutStopSec of 90 s and MaxInactivity = 1m,
    SIGKILL still arrives first; raise TimeoutStopSec or lower MaxInactivity
    if the timeout diagnostics are wanted in that case.

    Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From DaiTengu@1:103/705 to Git commit to main/sbbs/master on Wed Oct 14 20:32:26 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/d217da6f41ee2c4e931ecb7f
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Make RemoteIPHeader actually reach the access log
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell@1:103/705 to Git commit to main/sbbs/master on Wed Oct 14 20:32:26 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/574a32b0fdcd5033cce7267a
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Merge branch 'remoteipheader-access-log' into 'master'

    Make RemoteIPHeader actually reach the access log

    See merge request main/sbbs!735
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Thu Oct 22 10:11:17 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/6b8902bab7a555c145012dbc
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web Server: don't let lingering client sockets stall termination

    close_socket() half-closes the socket and then waits for the peer to
    close its side, for up to max_inactivity seconds in a single blocking
    call that ignored terminate_server. Clients that never close (abandoned
    scraper connections, typically) held each session thread there for up to
    a minute after its inactivity timeout. By then close_session_socket() had already removed the session from current_connections, so
    shutdown_sessions() could not reach it, and a server stop or recycle
    waited on these threads for minutes.

    Poll in one-second slices and stop waiting once terminate_server is set.
    The normal-operation bound is unchanged. This also applies to sockets
    the listener thread rejects (rate-limited, ip-silent.can, max clients),
    which go through the same function.

    Also, after "!TIMEOUT waiting for N active clients to disconnect", no
    longer follow it with "Done waiting for active clients to disconnect".

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Thu Oct 22 10:11:17 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/85b2ca4b23bad6e3786ca893
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web Server: don't keep a stale content handler after PathInfoIndex

    is_dynamic_req() runs once before a directory's webctrl.ini is read and
    again after PathInfoIndex resolves the request to the index script. The
    first pass, seeing the original path's extension (e.g. /robots.txt or
    /x.md), stored the matching web_handler.ini handler in req.xjs_handler,
    and the re-check never cleared it, so the handler (txt_handler.js, md_handler.js, ...) ran against the index script instead: the script's
    source was rendered as a text page, and requests that should reach the
    script never did. Clear the handler on every check.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Thu Oct 22 10:11:17 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/00ce71ebc56082e4af1c90e2
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web Server: fix doubled byte count for large non-chunked POSTs

    A non-chunked POST body larger than MAX_POST_LEN (4 MiB) is spooled to a
    temp file by post_to_file(), which adds each read to req.post_len. That
    field still held the Content-Length, so it ended at twice the body size
    and every such request logged a false "!ERROR Browser said they sent N
    bytes, but I got 2N". The following clamp to the Content-Length hid the
    error from everything else, so the stored body and the length seen by
    scripts were already correct.

    Zero post_len before spooling, as the chunked path already does.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Tue Nov 10 22:33:54 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/be39289cd8f8fc4e20597fa5
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    websrvr: reset parsed_vpath between requests on a keep-alive connection

    session->parsed_vpath is set when a request path falls under the file area virtual path prefix (FileVPathPrefix, e.g. /files/), but it lives in the session rather than in session->req, so close_request() never cleared it.
    Every later request on the same keep-alive connection was then treated as
    a file-area request by check_request(), which skips the "outside of web
    root" check and the entire webctrl.ini walk.

    Consequences:
    - AccessRequirements in webctrl.ini were bypassed. On wiki.synchro.net,
    GET /data/pages/wiki/syntax.txt returned 401 on its own, but 200 when
    sent after GET /files/ on the same connection.
    - Per-directory Rewrite, JSPreExec and [*.php] FastCGISocket settings were
    ignored, so a .php file fell back to the plain CGI handler from
    web_handler.ini, logging e.g. "CGI Error: .../wiki/index.php: line 1:
    /usr/local/bin/php-cgi: No such file or directory" in error.log.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Thu Nov 19 19:19:23 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/d7ce390ffa7c29afeeea9014
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    websrvr: keep an idle kept-alive HTTPS connection open

    Over HTTPS the server answered with "Connection: Keep-Alive" and then
    closed the connection as soon as it went back to read the next request
    and found it had not arrived yet. A browser that reused the connection
    after any pause lost the request (Safari does not resend a POST). Plain
    HTTP was not affected.

    sockreadline() and recvbufsocket() skip the wait for a readable socket
    while session->tls_pending is set, and tls_pending stays set after a
    request has been read. The next read went straight to cryptPopData(),
    which is non-blocking (CRYPT_OPTION_NET_READTIMEOUT is 0): with nothing received it returns CRYPT_OK with 0 bytes, or CRYPT_ERROR_TIMEOUT for a
    partial record. sess_recv() returned -1 for both, and the callers treat
    -1 on a TLS session as an error and close it. So a TLS session got no
    idle time at all: the next request, or the rest of a request line or
    POST body, had to be in hand already. The same "no data yet" case also
    hit session_check() (used to wait for more of a POST body), which took
    CRYPT_OK with 0 bytes from a partial record for a closed connection.

    Reading without a select() first goes back to the TLS support of
    dbbfabf1b1 (funky-27-foam, 2015-08-20); then cryptlib's default read
    timeout bounded the idle time. 98b9d23ddd (tight-73-wife, 2018-02-15)
    lowered it to 1 second "since we select() first anyway", and
    3be7d67b5f (flour-3-formed, 2018-03-13) to 0, which left no idle time.
    The session_check() case came with 50258e70bf (notion-31-talks,
    2026-06-04).

    Now sess_recv() clears tls_pending when cryptPopData() delivers nothing (CRYPT_OK with 0 bytes, or CRYPT_ERROR_TIMEOUT), and sockreadline() and recvbufsocket() then go back to waiting on the socket, up to
    MaxInactivity, as for a plain connection. A peer close or a TLS error (CRYPT_ERROR_COMPLETE, CRYPT_ERROR_READ) leaves tls_pending set and
    still ends the session at once. session_check() treats CRYPT_OK with 0
    bytes like CRYPT_ERROR_TIMEOUT: connected, no data yet.

    Reproduced and verified on a scratch web server on loopback with TLS
    (Python client, certificate checks off). Before: a second request on
    one TLS connection after a 0.3, 2 or 10 second pause got EOF, as did a
    request line or POST body sent in two parts with a pause (also when cut
    in the middle of a TLS record). After: two and five requests per
    connection with pauses of 0, 0.3, 2 and 10 seconds all answered,
    static and .ssjs, GET and POST; the split request line and POST bodies
    are read; an idle connection is closed after MaxInactivity with the
    "Session timeout due to inactivity" log line, as is half a request
    line; a client close (FIN alone or close_notify) ends the session
    thread as before; no CPU used while a connection waits; plain HTTP
    unchanged. As a plain one already did, an idle kept-alive HTTPS
    connection now holds its session thread, and delays a server shutdown,
    for up to MaxInactivity. Built with GCC only.

    Fixes #1370

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Fri Nov 20 15:25:23 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/4402dd90b746cc73cf22a61d
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    websrvr: end a session whose request body stops arriving

    A client that sent request headers with a Content-Length and then fewer
    body bytes than that held its session thread for as long as it kept the connection open, with no limit: MaxClients such connections, from anyone
    and before any authentication, stop the web server.

    recvbufsocket() waited for more body data with session_check(), which
    returns true both when data is readable and when the wait times out with nothing to read; the loop could not tell the two apart. Over HTTPS the
    read that followed found no record and went round again, each pass
    waiting MaxInactivity: this came with the keep-alive fix, d7ce390ffa (wave-63-zinc, 2026-11-19), which made "no TLS data yet" mean wait for
    more instead of close. Over plain HTTP the read that followed was a
    blocking recv() with no timeout at all, which is older.

    Now recvbufsocket() asks session_check() whether the socket is readable
    and, when the wait ended with nothing to read, logs "Session timeout due
    to inactivity" (as sockreadline() does for a request line or header) and
    closes the session. The bound is the idle time between pieces of the
    body, not the time for the whole body: a client that keeps sending stays connected. A plain recv() that returns EAGAIN now waits again instead of
    adding -1 to the byte count.

    sockreadline(), the other loop the keep-alive fix changed, already
    bounds each wait with socket_readable() and needs no change.

    Reproduced on a scratch web server on loopback (MaxInactivity 10 s,
    Python client): a POST with Content-Length 1000 and 500 body bytes, then silence. Before: over both HTTPS and HTTP the connection was still open,
    and the session thread still counted, when the client gave up after
    120 s. After: both closed after 10 s with the log line. A body sent in
    two halves 4 s apart is answered (both, before and after); a body that
    trickles one byte every 6 s stays connected, then is closed 10 s after
    the last byte. The keep-alive battery of the earlier fix (2 and 5
    requests per connection with pauses up to 10 s, split request line,
    request and POST body cut mid-TLS-record) passes unchanged. Built with
    GCC only.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Fri Nov 20 15:25:23 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/262a312abf6be850372beaa5
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    websrvr: do not run a request whose body never arrived

    read_post_data() read a body of known length (not chunked, at most MAX_POST_LEN) with recvbufsocket() and returned true whatever it got.
    When the body stopped arriving (the peer was idle past MaxInactivity, or
    closed the connection), recvbufsocket() closed the session socket and
    returned 0, and the request was handled anyway: the script ran with an
    empty body and its reply went to a closed socket. Now nothing read
    means no request: read_post_data() returns false, as it already did
    when a larger body (spooled to a file) or a chunk could not be read.
    Older than the earlier body-read fix, which made the wait end at
    MaxInactivity over HTTPS instead of never.

    Reproduced on a scratch web server on loopback (MaxInactivity 10 s),
    with a script that appends a line to a file each time it runs: a POST
    with Content-Length 1000 and 500 body bytes, then silence. Before: over
    HTTPS and plain HTTP the connection was closed after 10 s and the
    script still ran, each time with an empty body ("ran 0"). After: closed
    after 10 s, the script not run. A body sent in two halves 1 s apart
    runs it with all 1000 bytes, over HTTP and HTTPS. The keep-alive checks
    of the earlier fixes pass unchanged. Built with GCC only.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Sat Nov 21 13:56:31 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/2e943144fdb41fbd87319934
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web server: fix the invalid CGI/FastCGI headers fallback (#1383)

    When a CGI or FastCGI script's output doesn't begin with valid headers,
    the web server falls back to sending all of it as text/plain. That path
    had three bugs:

    - It sent uninitialized stack memory to the client. The fallback
    writes the raw lines saved in fbuf, which only the *nix pipe CGI
    reader filled: fastcgi_readln_out() ignored it and the Win32
    cgi_readln_out() passed NULL. fastcgi_readln_out() now copies the
    raw line into fbuf, the Win32 reader passes fbuf through, and
    do_cgi_stuff() initializes both line buffers and clears them when
    the script's output ends.

    - FastCGI stderr was parsed as the response. A newly read FCGI_STDERR
    record was reported as CGI_OUTPUT_READY instead of CGI_ERROR_READY,
    so its text was taken for a header line, invalidating the headers of
    any response preceded by a stderr record. php-fpm's reply for a
    missing script ("Primary script unknown", then Status: 404) went out
    as 200 with stack bytes, and so did an otherwise valid response that
    logged a warning first. FastCGI stderr is now logged, at warning
    level: it is the backend's diagnostic (php-fpm writes one for every
    request naming a missing script), so it no longer reaches error.log
    or the sysop's error notifications. Pipe CGI stderr stays at error
    level.

    - The fallback reply was unframed on a keep-alive connection: no
    Content-Length (any the script sent is discarded) and not chunked, so
    HTTP/1.1 clients waited for the inactivity timeout. It is now chunked
    when the normal path would chunk, and otherwise closes the connection.

    Tested on Linux against a stub FastCGI backend, HTTP/1.1 and 1.0:
    php-fpm's missing-script reply, a first line with no colon, a
    Content-Length followed by an invalid line, and a valid response after
    a stderr record. Before: stack bytes in every body, 200 instead of
    404, HTTP/1.1 hangs. After: correct status and body, chunked or closed
    framing, keep-alive reuse works, stderr logged as a warning. The Win32
    CGI change was not compiled.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Sat Nov 21 13:56:31 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/8922f648a7f74fc846e1cbfd
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web server: reduce absolute-form request targets to origin-form (#1382)

    For a request line like "GET http://host/path?query HTTP/1.1" (the
    absolute form, RFC 9112 3.2.2), get_request() took the host from the
    target and stripped the scheme and authority from physical_path only. virtual_path, request_line and orig_request_line kept the
    "http://host" prefix, and so did everything derived from them: the
    SCRIPT_NAME and REQUEST_URI given to CGI and FastCGI scripts, the request_string and virtual_path seen by webctrl.ini JS hooks, and the
    links in generated directory listings. php-fpm can't find a script
    whose SCRIPT_NAME is a URL, and rewrite rules written for "/..."
    paths never match.

    The target is now reduced to origin-form before any of those fields
    are set: the host (and vhost) still come from its authority, ahead of
    any Host header, and the target becomes "/path?query" ("/" when the
    authority is followed directly by a query or nothing). The scheme is
    matched on the target as received rather than after %-decoding.

    Tested on Linux with virtual hosts, old and new builds side by side: absolute-form requests (lower and upper case, with a port, https://,
    a Host header naming another vhost, no path before the query) now give
    FastCGI the same SCRIPT_NAME, REQUEST_URI and QUERY_STRING, and webctrl
    hooks the same request_string and virtual_path, as the equivalent
    origin-form request. "/http://..." paths are unaffected.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Sat Nov 21 13:56:31 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/706fdf4cb1b3db9370b7bb1e
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web server: parse the query and headers for JS without consuming them (#1381)

    js_parse_query() and parse_js_headers() tokenized the session's own
    buffers (req.query_str, req.post_data and req.headers[]) in place, and
    they run once for each webctrl.ini script (JSPreExec, each Rewrite) and
    again for an SSJS page. Every run after the first saw the query cut at
    its first '=' and no headers at all, and an internal redirect kept the
    damage: a Rewrite rule could not look at the query, cookies or
    User-Agent, and an .ssjs page in a directory with such scripts got a
    truncated http_request.query, an empty http_request.cookie and no http_request.header. Both functions now tokenize a copy.

    exec_ssjs() also clears http_request.query, .header and .cookie before
    parsing. The page's request object is set up before the webctrl.ini
    scripts run, and those scripts parse into the same objects, so with
    the query intact every value would otherwise appear twice.

    Tested on Linux with a JSPreExec and a Rewrite script that log what
    they see and a Rewrite that redirects internally to an .ssjs page:
    every script run and the page now see the full query, cookies and
    headers, each value once, whether reached directly or by the redirect,
    on a POST, and on a second request over the same connection. A page
    in a directory without webctrl.ini scripts is unchanged.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Sat Nov 21 13:56:31 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/beb5cc13e471ec65d5f5e7a5
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web server: write each access-log entry while holding its lock (#1380)

    The access-log thread locks the log, fprintf()s an entry into the
    FILE's buffer and unlocks it. The write() that puts the entry in the
    file happens later, after the unlock: when the buffer fills or when the
    queue goes idle. So the lock never covered a write. When web servers
    on more than one host share a log over SMB (ONE_HTTP_LOG and a shared
    data directory), each appends at the end of file as it last saw it,
    and a write based on a stale size lands on top of the other host's
    latest line, leaving a line cut off mid-field and merged with the next. Vertrauen's log had 5 to 30 such lines a day.

    Each entry is now written within the lock: seek to the end of the file
    after locking, which on a Linux CIFS mount re-reads the file's size
    from the server, and flush before unlocking.

    Two servers on one Linux host, sharing a log on a local file system and
    each sent 4000 concurrent requests, logged all 8000 entries intact
    before and after the change. Writers on the same host share one view of
    the file size, so that test cannot reproduce the cross-host overwrite;
    the fix applies to a host only when it runs this build.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Sat Nov 21 15:20:35 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/7a5005bddcecebdaccf8b163
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web server: log the requested Host at Informational level

    The Host header of each request was logged at Debug level, while the
    User-Agent was logged at Informational. A sysop tracking scrapers in
    the server log at Informational level saw the User-Agent but not the
    host it asked for, and turning on Debug logging for that adds far more
    volume. Log "Requested Host" at Informational, next to User-Agent.

    Fixes #1376

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Sat Nov 21 19:18:28 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/9b4047e66f0244e0b6fc54fa
    Modified Files:
    src/sbbs3/websrvr.cpp
    Log Message:
    Web Server: rename check_ars() to check_access()

    It does more than evaluate an access requirement string (ARS): it
    authenticates the user named in the Authorization header (password or
    Digest response, and account status), logs the session's user in or
    out, and only then checks file area access, the login requirements and
    the request's own requirements. Its one caller asks whether the request
    may proceed. No change in behavior.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)