• Add OIDC sign-in with WebFinger discovery and dynamic registration

    From Rob Swindell@VERT to GitLab note in main/sbbs on Tue Nov 24 22:12:24 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/e339f32d87b2b3025478c875832048a815c49848#note_11468

    ## Review (#1425)

    This fixes everything I found in the first version, c837a86c4c (lows-3-laugh, 2026-11-24): codes are now random, single-use and bound to a registered client and exact callback, with the client secret and S256 PKCE checked at the token endpoint; ID tokens carry proper PKCS#1 v1.5 padding; `sub` is a random per-slot value (and `newuserdat()` does delete `data/user/%04u.*`, so `####.oidc` and `####.apps.sqlite` go with a reused slot); the keyset password comes from `main.ini`; the issuer is fixed and HTTPS-only; failed password sign-ins go through `login()` and so through `session_badlogin()`. The `__Host-` cookies, CSRF tokens, CSP and consent screen are all good.

    What I found, most important first.

    ### 1. Blocking: no stock build gives SSJS or jsexec the `SQLite` class

    `js_CreateSQLiteClass()` is called only from `main.cpp` (terminal server), `services.cpp` and `jsdoor.cpp`. Neither `websrvr.cpp` nor `jsexec.cpp` creates it, so every endpoint, `oidc-admin.js init` and `test-provider.js` fail with `ReferenceError: SQLite is not defined` (that is what `test-provider.js` gives here). The README says the provider "needs SQLite in SSJS and jsexec", but no stock build provides that. Both need the class registered under `#ifdef USE_SQLITE`, and on Linux `USE_SQLITE` is only defined when `pkg-config sqlite3` succeeds, so a sysop also needs the SQLite development package at build time.

    `test-webfinger.js` passes (it does not open the database).

    ### 2. HTTP Basic client authentication is charged as a failed BBS login

    RFC 6749 section 2.3.1 says the authorization server MUST support HTTP Basic for clients issued a password (`client_secret_basic`), and it is the default in many client libraries (rack-oauth2, used by GitLab's OmniAuth strategy, defaults to it). The token endpoint accepts only `client_secret_post`, which discovery advertises, but a client that sends Basic anyway hits a worse problem than a refusal: the Web Server parses every `Authorization: Basic` header and looks the name up as a BBS user whether or not the location requires authentication (`check_access()` in `websrvr.cpp`). A client ID such as `gitlab` is an unknown user, so the request is logged as `!UNKNOWN USER` and counted by `session_badlogin()`. A misconfigured relying party can therefore get its own server's IP address temporarily banned by the login filter. Supporting `client_secret_basic` properly needs the Web Server to leave `Authorization` alone on these paths.

    ### 3. Open dynamic registration is on by default

    With no `[oidc]` section in `modopts.ini`, `dynamic_registrations_per_hour` is 60, so anyone can register a client without an account. The quota is one counter for the whole system, so one party can use it up and block everyone else; dynamic clients never expire, so the table only grows; and the consent screen shows a name the registrant chose (it can say "GitLab"). I would make it opt-in (default 0) and expire clients that are never used.

    ### 4. WebFinger publishes real name and location by default

    WebFinger reuses Finger's visibility switches, and the stock `[fingerservice]` section has `include_real_name = true` and `include_location = true` (and every missing switch defaults to true). Finger is a little-used, opt-in service; WebFinger is an HTTPS endpoint with `Access-Control-Allow-Origin: *` that anyone can query or crawl for every active account. I would give WebFinger its own switches, defaulting to off. It also tells anyone whether an account exists, as Finger does.

    ### 5. Runtime state in `ctrl/`, and shared `ctrl/` directories

    `ctrl/oidc.sqlite` holds the sysop's client registry (configuration) together with browser sessions, codes, access tokens and dynamic clients (generated state). Generated state belongs in `data/`. The issuer is also one row per database, so on a system where several hosts share `ctrl/` (Vertrauen's hosts do, over SMB) only one host name can pass the issuer check; the others get `invalid_request`. And SQLite's locking over a network share is the concern the README already notes.

    ### 6. UserInfo does not convert CP437 names

    `webfinger.ssjs` converts profile text with `profileText()` (CP437 to UTF-8 when the bytes are not already UTF-8), but `userinfo.ssjs` writes `u.alias`, `u.name` and `u.netmail` as they are. A CP437 name becomes invalid UTF-8 in the JSON response. The same conversion should be used there.

    ### 7. A webv4 cookie silently signs a user in to sysop-registered clients

    Sysop-registered clients (GitLab, in the README's example) get no consent screen, and `webIdentity()` accepts the webv4 `synchronet` cookie on its own. That cookie is the weakest session on the system (a plain-text key in `####.web` with no expiry; see #1398), so it is enough to sign in to GitLab without any prompt. I would accept it only for clients that show the consent screen, or not until #1398 replaces it.

    ### 8. `jwks.ssjs` unlocks the private key on every request

    To publish the public key, every unauthenticated request reads `main.ini`, opens the password-protected keyset and unwraps the private key, and `serve()` adds `Cache-Control: no-store` so clients cannot cache it. Storing the public JWK at `init` (in `settings`, say) and letting `jwks` and discovery be cached would remove that cost and keep the private key out of the public endpoint.

    ### 9. The webv4 validator path

    The fallback `libraryDir + "../../../webmail/lib/webv4.js"` resolves only in the source-tree layout. Elsewhere, unless the sysop copied `webv4.js` into `oauth/` as the README says, any request carrying a `synchronet` cookie (and no provider session) throws and returns 500. A copied `webv4.js` also stops tracking fixes to the original. Loading it from a fixed install location would avoid both.

    ### Smaller points

    - A replayed code is refused, but the access token from its first redemption stays valid; RFC 6749 section 4.1.2 says it SHOULD be revoked.
    - Discovery has no `end_session_endpoint`, and `GET /oauth/logout.ssjs` shows a confirmation form, so `after_sign_out_path` lands the user on a button rather than signing them out.
    - The session lifetimes (2 hours idle, 24 hours absolute) are constants; #1398 proposes making them configurable.
    - `serverSession()` assumes an `http_request.browser_session` object with `request_login()`, `logout()` and `auth_time`. #1398 has not defined that interface yet (it sketches `http_request.login(name, password, keep)`), so the two should be settled together there.
    - The key ID is always `"1"`, so there is no way to rotate the signing key without breaking clients that cached the old one.

    - *Authored by Claude (Claude Code), on behalf of @rswindell*

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net