open
https://gitlab.synchro.net/main/sbbs/-/work_items/1398
2026-11-22 12:32:32 -0800
## Summary
Add a browser session to the Web Server itself: a sign-in that the server owns, a session cookie it issues and checks, and the signed-in user made available to every request (static files, file areas, server-side JavaScript and CGI). The web applications that now each keep their own sign-in (webv4, WebMail, and optionally DokuWiki) could then use one sign-in and one sign-out, with one set of session rules.
## Today
The Web Server and the applications it serves use four unrelated ways to sign in (not counting the legacy web UI):
| | How the user signs in | Session |
|---|---|---|
| Web Server: `webctrl.ini` `AccessRequirements`, and restricted file areas under `FileVPathPrefix` (listed by `webfileindex.ssjs`) | HTTP Basic or Digest (the browser's own password prompt) | None: the credentials are sent with every request |
| webv4 | Its own form | `synchronet` cookie `<usernum>,<key>`; the key is kept in plain text in `data/user/####.web`; one session per user (signing in elsewhere ends the others); no expiry while the cookie lasts; every request calls `login()` with the password read from the user record |
| WebMail | Its own form, or from a webv4 session (`webv4_login`, `webv4_logout`, `webv4_only`, #1395) | `webmail` cookie; keys kept only as SHA-256 hashes in the user's `webmail.sessions.json`; several sessions per user; idle and absolute expiry; ended by a password change |
| DokuWiki (not a stock component, but used on Vertrauen's wiki) | DokuWiki's own form, through the `authsbbs` auth plugin | DokuWiki's PHP session |
Consequences:
- A user can be asked to sign in up to four times, and signing out of one leaves the others signed in. #1395 tied webv4 and WebMail together by hand; each further application would need the same.
- A webv4 or WebMail sign-in does not open a restricted file area or a location protected by `AccessRequirements`: those check only HTTP Basic/Digest.
- The session rules differ widely, and the weakest (webv4's plain-text key with no expiry) sets the protection of anything that trusts it (WebMail with `webv4_login`).
- The `authsbbs` DokuWiki plugin reads `user.tab` and compares the password itself, so a failed wiki sign-in is not counted by the BBS (no failed-login logging, no temporary ban) and the wiki accepts only the exact alias, not the forms the BBS's own login accepts (for example "digitalman" for "Digital Man").
## Proposal
The Web Server keeps browser sessions, as Apache httpd does with `mod_auth_form` and `mod_session`, and as the "forward auth" setups in front of nginx, Traefik and Caddy do:
1. **Sign-in and sign-out owned by the server.** A sign-in form (and a script method, for example `http_request.login(name, password, keep)`) checks the password the way the other servers do (same name lookup, same failed-login counting and filtering) and issues a session cookie: random key, `HttpOnly`, `Secure` when the request is HTTPS, `SameSite=Lax`, scoped to the host. A sign-out method ends it. A new session is issued at every sign-in (no session fixation), and the sign-in form needs protection against cross-site request forgery.
2. **Sessions kept on the server.** Only a hash of each key is stored (as WebMail's `session.js` does now); several sessions per user; idle and absolute expiry; a "keep me signed in" lifetime; every session of a user ends when the password changes; a list of a user's sessions, so a user (or sysop) can end them. WebMail's `webmail/lib/session.js` is close to the specification needed.
3. **The user resolved before anything else runs.** For each request with a valid session cookie, the server sets the request's user before checking `webctrl.ini` access rules or file-area access and before running any script, so:
- `AccessRequirements` and restricted file areas honor a browser session, not only HTTP Basic/Digest;
- server-side JavaScript gets `user` without handling a cookie itself;
- CGI programs get the standard `REMOTE_USER` (and `AUTH_TYPE`), which is how external applications such as DokuWiki can trust the server's sign-in.
4. **HTTP Basic and Digest stay**, for clients that are not browsers (download tools, scripts).
Then, each as its own step:
- **WebMail** uses the server session instead of its own cookie. `webv4_login`, `webv4_logout` and `webv4_only` become unnecessary on a host where both use it.
- **webv4** uses the server session instead of the `synchronet` cookie and the `data/user/####.web` key, which also removes the per-request `login()` with the stored password. The old cookie should be honored for a transition period, since sysops' webv4 mods and scripts assume it.
- **DokuWiki**: the `authsbbs` plugin implements `trustExternal()` (DokuWiki's hook for accepting a user the web server has already authenticated) and takes the user from `REMOTE_USER`. The wiki then never sees a password, its sign-ins are counted by the BBS, and every alias form the BBS accepts works. The name passed to DokuWiki must be normalized as `authsbbs` normalizes it now, so existing page history and ACLs (`@admin`, per-user rules) still match.
## Questions to settle
- **Host names.** Cookies are per host, and the wiki (wiki.synchro.net) and webv4 (web.synchro.net) are different hosts. Sharing one session across them needs a cookie for the parent domain, which every application on every subdomain would then receive. Options: sessions per host only (the default), an explicit setting for a parent-domain cookie, or a sign-in hand-off between hosts by redirect.
- **Shared fate.** With one session for a whole host, a cross-site scripting or request-forgery bug in any application there can act as the user everywhere on it, mail included. The server's defaults should follow WebMail's stricter rules (HTTPS-only option, idle expiry, `SameSite`), not webv4's.
- **Configuration.** Opt-in at first: per host or per directory (`webctrl.ini`), with the session lifetimes in `sbbs.ini` `[Web]` (and SCFG).
- **Storage.** Where the session table lives (per user under `data/user/####/`, as WebMail's is, or one file per server), and how it behaves when several BBS hosts share the data directory.
## Related
- #1395: webv4 and WebMail sign-in and sign-out tied together by hand.
- #1206: the web server never supported TLS-PSK authentication (dropped from the default `Authentication` list); HTTP Basic and Digest are its only sign-in methods.
- Prior art: Apache httpd `mod_auth_form` + `mod_session` (`mod_session_cookie`, `mod_session_crypto`, `mod_session_dbd`), `mod_auth_tkt`, `mod_auth_openidc`; nginx `auth_request`, Traefik ForwardAuth and Caddy `forward_auth` with oauth2-proxy, Authelia or Authentik; IIS forms authentication in integrated mode.
- *Authored by Claude (Claude Code), on behalf of @rswindell*
---
þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net