LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Remote desktop: security analysis, tests, docs and fixes from the VM run
Federico Pereira5836a0daf185
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9f79beb..7f19d66 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -50,6 +50,11 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),the selected sidebar row, an underline or a ring on the focused field, and bordered buttons. LordDefault looks as before; Classic uses smaller radii, borders and subtle highlights. Isolatedapps (Mail, Calendar, Contacts, Reminders, Passwords) follow it too.+- **Remote desktop: blocked and allowed addresses.** Settings → Sharing lists the addresses that+ are blocked, with the time left and an **Unblock** button, blocks an address or network by hand,+ and chooses who may connect: the **local network** (the default: private and link-local+ addresses and connections that arrive over a VPN of this computer), **only these addresses**, or+ **any address**. You get a notification when an address is blocked.### Changed@@ -74,6 +79,10 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),- **Debian's smartd stays off.** Installing smartmontools from Disks no longer leaves itsmonitoring daemon polling the disks every 30 minutes; Disks and the Monitor read SMART on demand.Administrators can opt back in (docs/SYSTEM.md, "smartd").+- **Remote desktop now accepts the local network only by default.** Connections from public+ internet addresses are refused unless you choose **Any address** (or list them) in Settings →+ Sharing; a VPN of this computer still works. Browsers signed in before the update sign in once+ more (the sign-in cookie changed).### Security@@ -94,6 +103,22 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),allows `AF_NETLINK`; it still creates no internet sockets). "No incoming connections" now alsocuts connections already accepted. The Raspberry Pi kernel build enables`CONFIG_INET_DIAG_DESTROY`; on a kernel without it the packets are still dropped.+- **Remote desktop: 3 failed sign-ins block the address.** For 15 minutes, then 1 hour, then 24+ hours if it happens again within a day (IPv6 counted per /64). Blocked addresses are cut before+ any TLS work and stay blocked after a restart (`/var/lib/lordos/remote/blocklist`, root only).+ Accounts are never locked (that would let anybody lock you out); repeated failures for one+ account only slow it down. Every failure and block goes to the journal (address and a sanitized+ user name, never the password).+- **Remote desktop: a full security review and hardening** ([docs/REMOTE.md](docs/REMOTE.md#security-analysis-083)).+ The page and the server check every field strictly (user names `a-z 0-9 _ -` up to 32, passwords+ 1–1024 bytes); the request, the form, the cookie, the WebSocket and the input messages are parsed+ strictly and refused otherwise; a wrong user name and a wrong password take exactly the same time;+ connections that are slow, too many from one address, or from addresses not allowed are closed+ early; the sign-in cookie is a `__Host-` cookie stored only as a hash, tied to the password (a+ password change or lock ends it) and ended for every browser of a user when that user locks the+ screen; sign-in and sign-out only accept requests from the page itself; TLS 1.2+ with AEAD+ ciphers only; the part that serves the desktop runs as the user with no shared state, no other+ descriptors and no way back to root. root can never sign in remotely.### Fixeddiff --git a/docs/REMOTE.md b/docs/REMOTE.mdindex 5071b2c..144363d 100644--- a/docs/REMOTE.md+++ b/docs/REMOTE.md@@ -29,6 +29,8 @@ The port is **5673**, which spells "LORD" on a phone keypad.with the one the browser shows.- **Who can connect:** all users, or only the `lordos-remote` group (`remote-config`;`remote-member` adds users to or removes them from the group).+- **Who can connect** and **Blocked addresses**: see [Blocked and allowed+ addresses](#blocked-and-allowed-addresses).- **Connected now:** user, IP, whether they're watching this screen or their own desktop, and forhow long, with a «Disconnect» button (`remote-kick`, only pids from lord-sessiond's list).@@ -49,17 +51,81 @@ and rounded fields. It has a language selector (es, en, pt) and an error shakes**It doesn't show the user list**: who has an account isn't revealed to the network. The avatartakes the initials of the name being typed.-- `POST /login`:+- `POST /login` (only from the page itself: `Origin` must be `https://` + `Host`):+ - the server checks every field again, strictly: the user name `^[a-z_][a-z0-9_-]{0,31}$`, the+ password 1–1024 bytes without NUL, exactly the fields `user` and `pass`, once each+ (`server/src/remote/rsec.c`); the page checks the same before sending;- it's verified against `/etc/shadow` (`getspnam` + `crypt_r`, constant-time comparison);- - only people's accounts: uid 1000–59999, with a shell, not locked or expired;- - never an account without a password, not even the live ISO's.-- **Per-IP waits:** the first two failures don't wait. After that, 1, 2, 4… seconds up to 5- minutes, plus a fixed 1 s on each failure. Measured: the 5th attempt reaches `?e=2` without- being verified.-- **Cookie** `lordos_remote`: 32 random bytes, `Secure; HttpOnly; SameSite=Strict`, 12 hours.-- **Headers:** strict `Content-Security-Policy`, `X-Frame-Options: DENY`,- `Referrer-Policy: same-origin`, `Cache-Control: no-store`.-- **Same origin:** the form and the WebSocket check `Origin` against `Host`.+ - only people's accounts: uid 1000–59999, a shell listed in `/etc/shells`, not locked, not+ expired, password not expired or due for a forced change, no `/etc/nologin`; **never root**+ (nor an account whose group is root's);+ - never an account without a password, not even the live ISO's;+ - a wrong user name, a refused account and a wrong password are answered exactly 1.25 s after+ the check began (unknown accounts spend the same `crypt` work on a dummy hash).+- **Lockout:** 3 failed sign-ins block the address (see [Blocked and allowed+ addresses](#blocked-and-allowed-addresses)). The old growing per-address waits stay as well.+- **Cookie** `__Host-lordos_remote`: 32 random bytes, `Secure; HttpOnly; SameSite=Strict; Path=/`,+ 12 hours. Only its SHA-256 is kept, with a digest of the account's shadow hash: changing or+ locking the password ends it. Locking the screen ends every cookie of that user. Signing out is a+ `POST /logout` from the page.+- **Headers:** `Content-Security-Policy` with the SHA-256 of the page's own script and style (no+ `unsafe-inline`), `frame-ancestors 'none'`, `form-action 'self'`; `X-Frame-Options: DENY`,+ `X-Content-Type-Options: nosniff`, `Referrer-Policy: same-origin`, `Cache-Control: no-store`,+ `Permissions-Policy` (no camera, microphone, location, USB…), `Cross-Origin-Opener-Policy` and+ `-Resource-Policy: same-origin`. No HSTS: with a self-signed certificate it would make the+ browser's warning impossible to get past.++++## Blocked and allowed addresses++**Lockout** (`server/src/remote/lockout.c`):++- 3 failed sign-ins from one address, without a successful one in between (within 24 hours),+ block it for **15 minutes**; blocked again within 24 hours, **1 hour**; then **24 hours**.+- IPv6 addresses count per **/64** (a host has a whole /64 to hop through).+- The answer to the third failure is the sign-in page with the "blocked" message; after that the+ address is closed right after `accept()`, before any TLS work.+- Blocks are kept in `/var/lib/lordos/remote/blocklist` (root, 0600, folder 0700) and survive a+ restart of `lord-sessiond` or of the computer.+- A successful sign-in clears that address's count. **Accounts are never locked** (anybody could+ lock you out); repeated failures for one user name, from any address, only slow it down: none for+ the first 4, then 1, 2, 4 and at most 8 s before checking.+- Each failure and each block is logged to the journal with the address and the attempted user+ name, cleaned to printable ASCII. Never the password.+- The user on the monitor gets a notification ("Remote desktop: address blocked") with a button+ that opens Settings → Sharing.++++**Who can connect** (Settings → Sharing, `net=` in `/etc/lordos/remote/config`):++- **Local network** (the default): private ranges (10/8, 172.16/12, 192.168/16, 100.64/10),+ loopback, link-local and IPv6 unique-local, plus connections that arrive on a VPN interface of+ this computer (`wg-`, `ovpn-`, `ips-`, `oc-`, `fvpn-`, `ppp`, `tun`). Public addresses are+ closed.+- **Only these addresses**: only the networks in the list.+- **Any address**: everyone who can reach the port (still with the lockout).++**Manual blocks** win over everything. The lists live in `/etc/lordos/remote/access` (root, 0600):+`allow <cidr>` and `block <cidr>`, at most 64 of each. Networks are IPv4 /8–/32 or IPv6 /16–/128;+host bits are cleared.++++++**Admin actions** (`remote_admin.c`, administrators only, validated on the root side by+`rs_cidr_parse`):++| Action | Argument | What it does |+|------------------------|---------------------|-----------------------------------------------------------------|+| `remote-config` | `net=lan\|list\|any` | the mode (with the existing `allow=`, `port=` lines) |+| `remote-block` | `<cidr>` | adds a manual block to `access` |+| `remote-unblock` | `<cidr>` | removes manual blocks inside it and appends `unblock <cidr>` to `/var/lib/lordos/remote/requests` (root 0600, `flock`); `lord-sessiond` lifts the lockout blocks inside it on SIGHUP |+| `remote-allow` | `add\|del <cidr>` | the "only these addresses" list |++Unblocking from Settings forgets that address's history (its next block is 15 minutes again).## Browser protocol (WebSocket `/ws`)@@ -91,6 +157,14 @@ session was locked).the monitor wins;- `ack`, `ping{ts}`.+**Validation** (`rs_ws_consume`, `rs_json_parse`, `rs_browser_input` in `rsec.c`): frames must be+masked, without RSV bits, with a known opcode and the shortest length encoding; control frames at+most 125 bytes and never fragmented; a message at most 2 MB (fragments are joined up to that);+text must be valid UTF-8; a binary message closes the connection (the page never sends one). Each+text message is one flat JSON object (known keys, integers or strings, no duplicates); positions+are clamped to the screen, key codes are keyboard keys only (1–248), the clipboard is at most 1 MB.+Anything else is ignored or closes with 1002/1007/1009.+**Compression:**- **Still screen:** PNG (lossless).@@ -103,27 +177,94 @@ state.## Process and privileges-1. `lord-sessiond` (root) accepts the connection and handles it in a child (up to 32 at a time).-2. That child does TLS and the login. With a valid cookie, it finds the user's session or creates- it (`sess.c`, with the same lock as the monitor).-3. **It drops root:** `initgroups`, `setgid`, `setuid`, and it's verified that it can't get it- back. TLS, compression and the bridge run as the user.+1. `lord-sessiond` (root) accepts the connection. Refused addresses (blocked, not allowed, too many+ connections) are closed there, before TLS. Otherwise a child handles it (48 at most, 8 per+ address; 32 signed-in browsers).+2. That child does TLS and reads one request under a 15 s deadline (a 90 s alarm backs it up). With+ a valid cookie, `/ws` finds the user's session or creates it (`sess.c`, with the same lock as+ the monitor).+3. **It forks the bridge, which drops root for good:** it unmaps `lord-sessiond`'s shared memory,+ closes every descriptor but the TLS socket, the session socket and a pipe to its parent, clears+ the environment, then `initgroups`, `setresgid`, `setresuid`, checks that the real, effective+ and saved ids are the user's and that it can't get root back, sets `no_new_privs`, not dumpable,+ and dies with its parent. TLS, compression and the bridge run as the user. The root parent keeps+ nothing of the connection: it only waits, and when the bridge reports that the session was+ locked, it ends every cookie of that user.OpenSSL (TLS) is only in `lord-sessiond`; `lord-server` doesn't link it. The certificate isself-signed P-256, with CN equal to the machine name and ten years of validity. It's in`/etc/lordos/remote/cert.pem` (`key.pem` 0600) and is created the first time remote is turned on.-## Threats (LAN)+## Threats| Threat | What's there ||----------------------------------------|------------------------------------------------------------------------------------------|-| someone listens on the network | TLS 1.2+; the certificate fingerprint is shown in Settings for comparison |-| password guessing | growing per-IP waits, 1 s per failure, logged to the journal |-| cookie theft | `HttpOnly`, `Secure`, `SameSite=Strict`, 12 h; locking the session invalidates it |-| another page uses the session (CSRF) | `Origin` = `Host` on `/login` and `/ws`; `frame-ancestors 'none'` |-| user enumeration | the login page doesn't list them; same message for wrong user and wrong password |-| bug in the bridge | it runs as the user who owns the session, not as root |-| access from the internet | not intended: use a VPN (Settings → Network → VPN). No port is opened on the router |+| someone listens on the network | TLS 1.2+ with AEAD ciphers only; the certificate fingerprint is shown in Settings |+| password guessing | 3 failures block the address (15 min, 1 h, 24 h), per-account slowdown, journal |+| guessing from many addresses | each address gets 2 tries before its block; the per-account slowdown caps the rate per user |+| user enumeration | no user list; same message and the same 1.25 s for unknown users and wrong passwords |+| cookie theft or fixation | `__Host-`, `HttpOnly`, `Secure`, `SameSite=Strict`, 12 h, stored hashed, new at each sign-in, ended by lock, logout and password change |+| another page uses the session (CSRF) | `Origin` = `https://` + `Host` required on `/login`, `/logout` and `/ws`; `frame-ancestors 'none'` |+| floods and slow clients | 20 new connections per address then 2/s, 8 open per address, 48 in all, 15 s to send the request |+| bug in the bridge | it runs as the user who owns the session, without root's shared state or descriptors |+| access from the internet | refused by default (local network only); use a VPN (Settings → Network → VPN) |++## Security analysis (0.8.3)++A review of everything the network can reach, done for 0.8.3: the HTTP parser, the login, the+cookie, CSRF, the WebSocket and the input messages, the privilege drop, resource limits, TLS,+headers, logging and the lock screen. Every finding below was fixed in the same release; the tests+are in `server/tests/remote_sec_test.c` (207 checks), `server/tests/remote_fuzz.c` (ASan+UBSan,+100,000 random and mutated inputs on every `make -C server test`), and the attack run on VM 122+listed after the table.++| # | Severity | What | Fix | Test |+|---|----------|------|-----|------|+| 1 | High | The 32-connection cap only counted signed-in browsers: any host could open unlimited connections, each a root child that waited up to 15 s per read (forever if bytes trickled in). | A child per connection only if the address is allowed, not blocked, within 20 new connections then 2/s, under 8 open from it and 48 in all; 15 s for handshake + request, 90 s alarm. | 14 parallel connections: 8 served; 60 quick requests: 8 served, 52 refused; one header byte per second: cut at 16.1 s; TCP without a TLS handshake: cut at 15.0 s. |+| 2 | High | After dropping root the bridge still had `lord-sessiond`'s shared memory mapped read-write: it could forge a cookie for any other user, erase blocks, hold the lock (freezing the root process) or plant a pid that root later signalled when remote was turned off (`kill(-1)` = every process). | The bridge is forked after the handshake and unmaps it; root only signals pids from its own private list. | `/proc` of a live bridge: uid 1003 (real, effective, saved), no shared mapping, fds 0–2 + socket + session + pipe, `NoNewPrivs 1`. |+| 3 | Medium | User enumeration by timing: an unknown or refused account returned before `crypt`, a wrong password after it. | Dummy hash with the same algorithm and cost; every failure answered 1.25 s after the check began. | 8–24 tries each: unknown 1254.2 ms, existing user with a wrong password 1254.1 ms, `root` 1254.6 ms, a system account 1254.8 ms (medians). |+| 4 | Medium | No lockout (only growing waits, in a 64-entry table an attacker could cycle); no restriction on where connections came from. | Lockout per address (/64 for IPv6), 15 min → 1 h → 24 h, persistent; local network only by default; manual lists. | 3 wrong → blocked page, 4th refused before TLS; still blocked after restarting `lord-sessiond`; unblocked from Settings; "only these addresses" refused the Pi and served the listed Mac. |+| 5 | Medium | A request without `Origin` passed the same-origin check; logout was a `GET` (any site could sign you out). | `Origin` required and equal to `https://` + `Host` on `/login`, `/logout`, `/ws`; `Sec-Fetch-Site` must agree; logout is a `POST`. | foreign `Origin`, `http://` origin, none, `cross-site`: 403; `GET /logout`: 405. |+| 6 | Medium | Cookie: matched by substring (`xlordos_remote=` counted), no `__Host-` prefix (another service on the same host could plant one), kept in clear in shared memory, unaffected by a password change. | `__Host-lordos_remote`, exact parse, two of them refused, only SHA-256 stored, bound to the shadow hash, the old cookie dropped at sign-in. | forged, old name, duplicated: 403; after `chpasswd` and after logout: 303 to the sign-in page / 403 on `/ws`. |+| 7 | Medium | Locking the screen ended only the cookie of the browsers connected at that moment; a browser signed in earlier could come back to the session. | Lock ends every cookie of that user (the root process for a lock on the monitor, the bridge's root parent otherwise). | a second, unconnected cookie: 200 before the lock, refused after. |+| 8 | Low | HTTP parser: last duplicate header won, `Content-Length` read with `atol`, `Transfer-Encoding` ignored, bare LF, folding, any method served pages, bytes after the body accepted. | `rs_parse_head`: strict request line, 40 headers, 8 KB head, duplicates refused, `Transfer-Encoding` → 501, 4 KB body, one request per connection, method per path. | 22 malformed requests answered 400/405/413/414/415/431/501 as expected. |+| 9 | Low | Form parser: first duplicate won, `%00` cut the value, long values truncated silently, unknown fields ignored, no `Content-Type` check, 256-byte password limit. | `rs_parse_login`: exactly `user` and `pass`, strict `%XX`, user name rules, password 1–1024 bytes, no NUL; form type required; no query on `/login`. | 33-character name, 1025-byte password, `%00`: refused (and counted); duplicate/unknown field, `%zz`: 400; `text/plain`: 415. |+| 10 | Low | WebSocket: no RSV/opcode/length checks, pings up to 2 MB echoed back, fragments silently dropped, no UTF-8 check. | `rs_ws_consume` (see Browser protocol). | unmasked frame → close 1002; fuzzed. |+| 11 | Low | Input messages were read with `strstr` (a string could smuggle `"x":` into a number); `BTN_*` codes up to 0x2ff accepted as keys. | Strict flat JSON; keys 1–248; all values clamped. | unit tests. |+| 12 | Low | TLS used OpenSSL's default list (CBC suites in TLS 1.2), compression and renegotiation defaults; key permissions not checked. | ECDHE-ECDSA AES-GCM / ChaCha20-Poly1305 only, TLS 1.3 AEAD suites, X25519/P-256/P-384, no compression or renegotiation, server order; `key.pem` forced to root 0600. | TLS 1.0/1.1: protocol alert; TLS 1.2 accepts exactly the 3 AEAD suites; TLS 1.3 the 3 standard ones (CCM refused); compression none. |+| 13 | Low | CSP allowed inline scripts; no `Permissions-Policy`, COOP or CORP. | Hash-based CSP, `form-action`, `base-uri`, the rest of the headers. `Referrer-Policy` stays `same-origin`: with `no-referrer` browsers send `Origin: null` on the page's own form. | header dump; Chrome sign-in works under the CSP. |+| 14 | Low | Accounts: shells matched by substring only, root-group accounts allowed, `/etc/nologin`, forced password change and expired passwords ignored. | Shell from `/etc/shells`, no gid 0, never `root`, the shadow aging rules. | `root` refused like a wrong password. |+| 15 | Low | Log injection: `Origin`/`Host` logged raw (a bare LF forged a journal line); attempted names logged only when valid. | Everything logged is cleaned to printable ASCII; attempted names logged sanitized. | journal check. |+| 16 | Info | The privilege drop didn't check saved ids or groups, kept the environment and every inherited descriptor, and the bridge outlived `lord-sessiond` (the parent-death signal is cleared by `setuid`). | See "Process and privileges". | `/proc` check above. |+| 17 | Info | After a failure the user name went into the URL (`/?e=1&u=…`): a password typed into the user field ended up in the history. | The page keeps the name in `sessionStorage` and clears the address bar. | browser check. |++**Greeter and lock.** A remote browser can't unlock the monitor: the monitor shows the login+screen (a separate `lord-server` as `lordos-greeter`), and the session only reaches `lord-sessiond`+through the seat connection, whose requests are lock, switch user and power. Signing in from the+browser resumes the user's session in the background, never on the monitor. Locking the monitor+ends the remote viewers and every remote cookie of that user; a browser must sign in again with the+password. Locking from the browser does the same.++**What stays as it is.** `lord-sessiond` reads `/etc/shadow` itself instead of PAM (no PAM stack+to configure; the account rules PAM would apply are listed under Login). The certificate is+self-signed: compare the fingerprint the first time. An attacker on the LAN with many addresses+gets 2 tries per address; the per-account slowdown limits that. Two-step sign-in is a proposal in+`ROADMAP.md`.++**Attack run (VM 122, Debian 13, October 19)** from the development Mac (172.17.0.5) and the+Raspberry Pi (172.17.0.24) with a stdlib Python client, OpenSSL's `s_client` on the VM, and a+headless browser for the pages: normal sign-in, desktop over WebSocket and sign-out; brute force+and persistence; timing; 22 malformed requests; CSRF; WebSocket without, with forged, logged-out,+duplicated or out-of-date cookies, wrong key, version or origin; slowloris; connection flood; TLS+scan; headers; lock. All results are in the table.++++++++## Measurements (VM 118: Xeon Silver 4108 at 1.8 GHz, 4 cores, no GPU, 1280×800)@@ -254,13 +395,16 @@ the internet, use a VPN instead of opening the port.| Path | What it is ||---------------------------------------|------------------------------------------------------------|| `server/src/remote/conn.c` | one connection: HTTP, login, WebSocket, bridge |+| `server/src/remote/rsec.c` | strict parsers: request head, form, cookie, WebSocket, JSON |+| `server/src/remote/ipnet.c`, `lockout.c` | addresses and networks, lockout and connection rate || `server/src/remote/enc.c` | PNG/JPEG (stb_image_write, vendored in third_party/stb) || `server/src/remote/login.html`, `client.html` | pages (embedded in the binary) || `server/src/remote/remote_admin.c` | `remote-*` actions || `server/src/remote/ssh_admin.c` | `ssh-*` actions (remote login) || `tools/iso/rootfs/etc/ssh/sshd_config.d/10-lordos.conf` | sshd defaults shipped by the `lordos` package || `apps/settings/Sharing.jsx`, `sdk/remote.js` | Settings → Sharing and the notice on the monitor |-| `/etc/lordos/remote/` | `config`, `cert.pem`, `key.pem`, `fingerprint` |+| `/etc/lordos/remote/` | `config`, `access`, `cert.pem`, `key.pem`, `fingerprint` |+| `/var/lib/lordos/remote/` | `blocklist`, `requests` (root only) |## Screenshotsdiff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 4f4ee67..c5ed55b 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -594,6 +594,12 @@ Details in `MAIL.md`. Tested on VM 123 against local Dovecot, Postfix and Radica- Measured against today's numbers (`REMOTE.md`), with an external security review of the newnetwork surface.+- [ ] **Two-step sign-in (TOTP) for the remote desktop** — proposal (0.8.3 security review,+ `REMOTE.md`): an optional one-time code from an authenticator app after the password, enabled+ per user in Settings → Users (secret stored by `lord-sessiond` in a root-only file, QR shown once,+ recovery codes), checked in the same constant-time path, and counted by the same lockout. Off by+ default; required for "Any address".+- [ ] **Immutable edition (A/B system images)** — 0.8.2 published the design study and anexperimental, VM-verified prototype (`IMMUTABLE.md`, `tools/immutable/`): read-only `/usr` withdm-verity in two slots, one boot image per version, automatic fallback, `/etc` and `/home` kept.diff --git a/docs/VM-SETUP.md b/docs/VM-SETUP.mdindex eb958fb..e95b41c 100644--- a/docs/VM-SETUP.md+++ b/docs/VM-SETUP.md@@ -1295,3 +1295,20 @@ The installed tree was saved first in `/var/backups/lordos-classic-bak` and put`~/.config/lordos/settings.json` restored from its copy, `~/.cache/lordos-shot*.json`,`~/shot-harness`, `~/deploy-classic-119.sh` and `~/LordOS-classic` deleted. The VM ends at thelogin screen.++## Step 36 — Remote desktop security review (VM 122 `lordos-sandbox`, October 19)++See `REMOTE.md`, "Security analysis (0.8.3)". On VM 122 (172.17.0.56), tree in+`~/LordOS-remotesec`, built there (`make -C server`, `make -C server test`) and installed over the+package's files by `~/deploy-remotesec-122.sh` (it saved `/usr/lib/lordos`, `/etc/lordos` and+`/var/lib/lordos/remote` to `/var/backups/lordos-remotesec-20261019` first).++- **Nothing installed.** The attacks ran from the development Mac (stdlib Python client in the+ scratchpad, a throwaway headless Chrome profile for the screenshots) and from the Raspberry Pi+ (the same Python script over SSH stdin); OpenSSL's `s_client` on the VM did the TLS scan.+- **Test-only account `rtest`** (password only for these tests), temporarily in `sudo` and the+ autologin user, so the block notification reached the monitor's session; removed at the end.+- `~/unblock-remotesec-122.sh <cidr>` writes the same request as the `remote-unblock` action.+- **Undone at the end:** the package's files restored from the backup, `/etc/lordos` restored+ (`session.conf` back to `AUTOLOGIN=`, remote config as before), `/var/lib/lordos/remote` removed,+ `rtest` and its home deleted, `lordos.service` restarted to the login screen. Network untouched.diff --git a/docs/remote-desktop-block-notice.png b/docs/remote-desktop-block-notice.pngnew file mode 100644index 0000000..3bca300Binary files /dev/null and b/docs/remote-desktop-block-notice.png differdiff --git a/docs/remote-desktop-login-blocked.png b/docs/remote-desktop-login-blocked.pngnew file mode 100644index 0000000..a7b48d7Binary files /dev/null and b/docs/remote-desktop-login-blocked.png differdiff --git a/docs/remote-desktop-login-invalid.png b/docs/remote-desktop-login-invalid.pngnew file mode 100644index 0000000..f362fcbBinary files /dev/null and b/docs/remote-desktop-login-invalid.png differdiff --git a/docs/remote-desktop-login-wrong.png b/docs/remote-desktop-login-wrong.pngnew file mode 100644index 0000000..18c962eBinary files /dev/null and b/docs/remote-desktop-login-wrong.png differdiff --git a/docs/settings-sharing-allowlist-dark.png b/docs/settings-sharing-allowlist-dark.pngnew file mode 100644index 0000000..12b9978Binary files /dev/null and b/docs/settings-sharing-allowlist-dark.png differdiff --git a/docs/settings-sharing-allowlist-light.png b/docs/settings-sharing-allowlist-light.pngnew file mode 100644index 0000000..177ae96Binary files /dev/null and b/docs/settings-sharing-allowlist-light.png differdiff --git a/docs/settings-sharing-blocked-dark.png b/docs/settings-sharing-blocked-dark.pngnew file mode 100644index 0000000..9cad777Binary files /dev/null and b/docs/settings-sharing-blocked-dark.png differdiff --git a/docs/settings-sharing-blocked-light.png b/docs/settings-sharing-blocked-light.pngnew file mode 100644index 0000000..53ecea4Binary files /dev/null and b/docs/settings-sharing-blocked-light.png differdiff --git a/server/src/remote/conn.c b/server/src/remote/conn.cindex 070eeb8..da3dff8 100644--- a/server/src/remote/conn.c+++ b/server/src/remote/conn.c@@ -69,6 +69,14 @@ static double mono(void) {return (double)t.tv_sec + t.tv_nsec / 1e9;}+/* A failed login is answered exactly FAIL_SECONDS after the password check began, whatever the+ * account (unknown, refused or a wrong password): the time says nothing about who exists. */+#define FAIL_SECONDS 1.25+static void sleep_until(double t) {+ struct timespec ts = { (time_t)t, (long)((t - (double)(time_t)t) * 1e9) };+ while (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL) == EINTR) {}+}+/* ---- blocking TLS I/O (before the bridge) ---- */static int wait_io(int out) {@@ -76,7 +84,7 @@ static int wait_io(int out) {double left = deadline - mono();if (left <= 0) return -1;struct pollfd p = { sock, (short)(out ? POLLOUT : POLLIN), 0 };- int ms = left > 10 ? 10000 : (int)(left * 1000) + 1;+ int ms = (int)(left * 1000) + 1;return poll(&p, 1, ms) > 0 ? 0 : -1;}@@ -144,7 +152,8 @@ static const char *status_text(int code) {}}-/* Every answer: no caching, no framing, no referrer, no sniffing, no powerful features, and a CSP+/* Every answer: no caching, no framing, no referrer to other sites (same-origin, not no-referrer: with+ * no-referrer browsers send "Origin: null" on our own form posts, and the Origin check needs it), no sniffing, no powerful features, and a CSP* that only lets the page's own inline code run (or nothing, for non-HTML answers). No HSTS: the* certificate is self-signed, and HSTS would make its warning impossible to get past. */static void respond_page(int code, const char *type, const char *extra, const char *body, size_t len, const Page *pg, const char *host) {@@ -161,7 +170,7 @@ static void respond_page(int code, const char *type, const char *extra, const chint n = snprintf(head, sizeof head,"HTTP/1.1 %d %s\r\nContent-Type: %s\r\nContent-Length: %zu\r\nConnection: close\r\n""Cache-Control: no-store, max-age=0\r\nPragma: no-cache\r\n"- "X-Frame-Options: DENY\r\nX-Content-Type-Options: nosniff\r\nReferrer-Policy: no-referrer\r\n"+ "X-Frame-Options: DENY\r\nX-Content-Type-Options: nosniff\r\nReferrer-Policy: same-origin\r\n""Cross-Origin-Opener-Policy: same-origin\r\nCross-Origin-Resource-Policy: same-origin\r\n""Permissions-Policy: camera=(), microphone=(), geolocation=(), usb=(), serial=(), hid=(), bluetooth=(), payment=(), display-capture=()\r\n""Content-Security-Policy: %s\r\n%s\r\n", code, status_text(code), type, len, csp, extra ? extra : "");@@ -376,10 +385,11 @@ static void push_notice(const char *key, double until, int strikes) {static void handle_login(const RsReq *r) {if (r->query[0]) { respond(400, NULL); return; } /* credentials never travel in a URL */if (!origin_ok(r)) {- char o[64], h[64];+ char o[64], h[64], f[24];rs_log_clean(r->origin, strlen(r->origin), o, sizeof o);rs_log_clean(r->host, strlen(r->host), h, sizeof h);- sd_log("login refused: origin \"%s\" is not https://%s", o, h);+ rs_log_clean(r->fetch_site, strlen(r->fetch_site), f, sizeof f);+ sd_log("login refused: not from this page (Origin \"%s\", Host \"%s\", Sec-Fetch-Site \"%s\")", o, h, f);respond(403, NULL);return;}@@ -401,10 +411,12 @@ static void handle_login(const RsReq *r) {}int ok = 0;char ukey[40] = "";+ double t0 = mono();if (fr == RS_FORM_OK) {snprintf(ukey, sizeof ukey, "u:%s", user);double d = rl_user_delay(sd_fail_count(ukey)); /* per account: slower, never locked */if (d > 0) sleep((unsigned)d);+ t0 = mono();ok = sd_check_password(user, pass, 1);}explicit_bzero(pass, sizeof pass);@@ -423,11 +435,11 @@ static void handle_login(const RsReq *r) {if (blocked) {sd_log("blocked %s for %.0f minutes after %d failed logins (block %d in 24 h)", peer_key, (until - rd_now()) / 60 + 0.5,RL_FAILS, strikes);- sleep(1);+ sleep_until(t0 + FAIL_SECONDS);send_login(403, 4, r->host);return;}- sleep(1);+ sleep_until(t0 + FAIL_SECONDS);redirect("/?e=1", NULL);return;}@@ -986,7 +998,7 @@ void rd_serve(SSL_CTX *ctx, int fd, const char *ip, const char *key) {snprintf(p, sizeof p, "%s", rd_conf.greeter_theme);char *slash = strrchr(p, '/');if (slash) snprintf(slash, sizeof p - (size_t)(slash - p), "/assets/background.jpg");- int f = open(p, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);+ int f = open(p, O_RDONLY | O_CLOEXEC); /* a fixed path in root's theme folder (a link to the wallpaper) */struct stat st;char *img = NULL;size_t got = 0;diff --git a/server/src/remote/login.html b/server/src/remote/login.htmlindex 6a7eff3..4e98c69 100644--- a/server/src/remote/login.html+++ b/server/src/remote/login.html@@ -46,7 +46,7 @@</head><body><div class="top"><div class="date" id="date"></div><div class="clock" id="clock"></div></div>-<form method="post" action="/login" enctype="application/x-www-form-urlencoded" accept-charset="UTF-8" autocomplete="on" id="f">+<form method="post" action="/login" enctype="application/x-www-form-urlencoded" accept-charset="UTF-8" autocomplete="on" novalidate id="f"><div class="avatar" id="av">👑</div><div class="who" id="who"></div><div class="field"><input id="user" name="user" type="text" autocomplete="username" autocapitalize="none" autocorrect="off" spellcheck="false" inputmode="text" maxlength="32" pattern="[a-z_][a-z0-9_\-]{0,31}" required autofocus></div>diff --git a/server/src/remote/sessiond.c b/server/src/remote/sessiond.cindex 7c54792..2c59d77 100644--- a/server/src/remote/sessiond.c+++ b/server/src/remote/sessiond.c@@ -28,6 +28,7 @@#include "sessiond.h"#include "../sec/cgroup.h"#include "proto.h"+#include "rsec.h"#include <ctype.h>#include <dirent.h>@@ -975,6 +976,12 @@ static void unblock_requests(void) {rd_lock();int k = rl_unblock(&rd_shared->lockout, net);if (k) { rd_shared->lockout_dirty = 1; rd_shared->version++; }+ /* and the growing per-source waits of those sources start over */+ RsCidr req, fk;+ if (!rs_cidr_parse(net, &req))+ for (int i = 0; i < 128; i++)+ if (rd_shared->fails[i].key[0] && !rs_key_parse(rd_shared->fails[i].key, &fk) &&+ (rs_cidr_covers(&req, &fk) || rs_cidr_covers(&fk, &req))) memset(&rd_shared->fails[i], 0, sizeof rd_shared->fails[i]);rd_unlock();char clean[64];rs_log_clean(net, strlen(net), clean, sizeof clean);diff --git a/server/tests/remote_fuzz.c b/server/tests/remote_fuzz.cindex e34312d..d2c8a23 100644--- a/server/tests/remote_fuzz.c+++ b/server/tests/remote_fuzz.c@@ -121,7 +121,7 @@ static size_t ws_stream(unsigned char *b, size_t cap) {else if (len < 65536) { b[o++] = 0x80 | 126; b[o++] = (unsigned char)(len >> 8); b[o++] = (unsigned char)len; }else { b[o++] = 0x80 | 127; for (int i = 0; i < 8; i++) b[o++] = (unsigned char)((unsigned long long)len >> (56 - 8 * i)); }for (int i = 0; i < 4; i++) b[o++] = (unsigned char)rnd();- for (size_t i = 0; i < len; i++) b[o++] = (unsigned char)(rnd() % 3 ? "{\"t\":\"m\",\"x\":1}"[i % 15] : rnd());+ for (size_t i = 0; i < len; i++) b[o++] = (unsigned char)(rnd() % 3 ? (unsigned)(unsigned char)"{\"t\":\"m\",\"x\":1}"[i % 15] : rnd());}return o;}