Skip to content

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.

Security: LordOS's search, sheets and system prompts take the keyboard from Linux apps

Federico Pereiradcb8293ea75b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8a707dd..dfc16c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -148,6 +148,12 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
### Security
+- **Keys typed into LordOS's own prompts no longer reach the Linux app in front.** What you typed
+ into the search, the app launcher, a sheet or a system prompt (the keyring password, a permission
+ prompt, the file chooser) was also delivered to the Linux (Wayland) app whose window was in front,
+ so that app could read a password typed into the keyring prompt. While any of them is open, Linux
+ apps now get no keys at all; menus and the clipboard and emoji panels still type into the app
+ ([docs/PRIVACY.md](docs/PRIVACY.md#system-prompts-take-the-keyboard-082)).
- **Mail, Calendar, Contacts and Reminders run in their own sandboxed process.** Like Passwords
and installed apps, each one is now `lord-server --app <id>` with Landlock, seccomp, no network
and its own cgroup scope, instead of running inside the desktop's process. Mail's window can read
diff --git a/docs/LAYERS.md b/docs/LAYERS.md
index e1779ee..f386ec9 100644
--- a/docs/LAYERS.md
+++ b/docs/LAYERS.md
@@ -80,6 +80,11 @@ import { Layer, Overlay, LAYERS } from '@lordos/sdk';
- Used today by: the shell's menus, the SDK's `MenuButton`, the «fill from Passwords» button
(`AutofillButton`), Settings' pop-up buttons and Passwords' pop-up menus. Calendar, Contacts and
Reminders keep their own per-window popover host; the Terminal's preferences use an inline list.
+- **The keyboard (0.8.2).** While anything shows in the `overlay`, `modal` or `system` layers (search,
+ the launcher, sheets, system prompts), no Linux app gets the keys: `runtime/index.js` counts each
+ layer's children after every commit and `sdk/wayland.js` gives the compositor keyboard focus 0
+ ([PRIVACY.md](PRIVACY.md#system-prompts-take-the-keyboard-082)). `popover` (menus, the clipboard and
+ emoji panels, which paste into the app in front) keeps the app's keyboard.
- **Don't** fight the order with large `zIndex` values: they only order siblings. A new kind of
surface gets a row in the table above (and in `sdk/layers.js`) instead.
diff --git a/docs/PRIVACY.md b/docs/PRIVACY.md
index 4bc3319..b75f1db 100644
--- a/docs/PRIVACY.md
+++ b/docs/PRIVACY.md
@@ -420,6 +420,22 @@ through `globalThis.__lordos.monitorDevices`.
| `sdk/sysopen.js` | the session opens attachments and apps for the isolated system apps |
| `server/tests/brokermail_test.c` | `build/brokermail-test` |
+## System prompts take the keyboard (0.8.2)
+
+Until 0.8.1, keys typed into LordOS's search, the app launcher, a sheet or a system prompt (the
+keyring/password prompt, a permission prompt, the file chooser) were also delivered to the Linux
+(Wayland) app in front: the compositor's keyboard focus followed the top window, not what LordOS
+drew above it, so a Linux app could read a password typed into the keyring prompt. Now, while
+anything shows in the `overlay`, `modal` or `system` layers ([LAYERS.md](LAYERS.md)),
+`runtime/index.js` reports it after each React commit and `sdk/wayland.js` sets the compositor's
+keyboard focus to no surface (`lord.wayland.focus(0)`); when the last of them closes, the top window
+gets the keyboard back. Menus and the clipboard and emoji panels (`popover`) don't take it: they paste
+into the app in front.
+
+Check: `server/tests/keyfocus/shellkeys.sh` runs `tools/diag/keylag-client` (a Wayland window that
+counts `wl_keyboard.key` presses) while keys are typed; with the search open it must count 0 (see
+[ISO.md](ISO.md), release test 0.8.2).
+
## System apps in their own process (0.8.2)
Mail parses mail from anyone; Calendar, Contacts and Reminders show invitations, `.ics` and
diff --git a/runtime/index.js b/runtime/index.js
index 77e90f2..b11594f 100644
--- a/runtime/index.js
+++ b/runtime/index.js
@@ -114,11 +114,11 @@ const host = {
},
appendInitialChild(parent, child) { lord.appendChild(parent.id, child.id); attach(parent, child); },
appendChild(parent, child) { lord.appendChild(parent.id, child.id); attach(parent, child); },
- appendChildToContainer(container, child) { lord.appendChild(container.id, child.id); attach(container, child); },
+ appendChildToContainer(container, child) { lord.appendChild(container.id, child.id); attach(container, child); layerCount(container, 1); },
insertBefore(parent, child, before) { lord.insertBefore(parent.id, child.id, before.id); attach(parent, child); },
- insertInContainerBefore(container, child, before) { lord.insertBefore(container.id, child.id, before.id); attach(container, child); },
+ insertInContainerBefore(container, child, before) { lord.insertBefore(container.id, child.id, before.id); attach(container, child); layerCount(container, 1); },
removeChild(parent, child) { lord.removeChild(parent.id, child.id); },
- removeChildFromContainer(container, child) { lord.removeChild(container.id, child.id); },
+ removeChildFromContainer(container, child) { lord.removeChild(container.id, child.id); layerCount(container, -1); },
detachDeletedInstance(inst) { unregister(inst); lord.destroy(inst.id); },
clearContainer() {},
@@ -137,7 +137,7 @@ const host = {
getChildHostContext: (ctx) => ctx,
getPublicInstance: (inst) => inst,
prepareForCommit: () => null,
- resetAfterCommit() {},
+ resetAfterCommit() { layersCommitted(); },
preparePortalMount() {},
setCurrentUpdatePriority(p) { updatePriority = p; },
getCurrentUpdatePriority: () => updatePriority,
@@ -175,6 +175,28 @@ const host = {
const reconciler = Reconciler(host);
+// ---- what is open in the layers that take the keyboard ----
+// The search, the app launcher, shell sheets and system prompts (keyring, permissions, the file
+// chooser) live in the overlay, modal and system layers (sdk/layers.js). While any of them shows
+// something, the keyboard is LordOS's: no Linux app (Wayland or X11) gets the keys typed into it
+// (sdk/wayland.js asks the compositor; docs/PRIVACY.md).
+const KEYBOARD_LAYERS = new Set([40, 60, 100]); // overlay, modal, system
+let keyboardBusy = false;
+const keyboardWatchers = new Set();
+function layerCount(container, d) {
+ if (!container.layer) return;
+ container.count = Math.max(0, (container.count || 0) + d);
+}
+function layersCommitted() {
+ let busy = false;
+ for (const [z, c] of layerNodes) if (KEYBOARD_LAYERS.has(z) && c.count > 0) { busy = true; break; }
+ if (busy === keyboardBusy) return;
+ keyboardBusy = busy;
+ for (const fn of keyboardWatchers) { try { fn(busy); } catch (e) { console.error(e); } }
+}
+export const shellHasKeyboard = () => keyboardBusy;
+export function onShellKeyboard(fn) { keyboardWatchers.add(fn); return () => keyboardWatchers.delete(fn); }
+
// ---- layers: one stacking order for the whole screen (sdk/layers.js, docs/LAYERS.md) ----
// Each layer is a root node of the screen's size, above the React tree (zIndex > 0) and
// pointerEvents 'box-none' (lord-server never hits the layer itself, only what is in it), so paint
@@ -188,7 +210,7 @@ export function layerContainer(z) {
for (const [k, v] of [['position', 'absolute'], ['left', 0], ['top', 0], ['width', screen.width], ['height', screen.height],
['pointerEvents', 'box-none'], ['zIndex', z]]) lord.setStyle(id, k, v);
lord.appendChild(rootNode, id);
- c = { id, isContainer: true };
+ c = { id, isContainer: true, layer: z, count: 0 };
layerNodes.set(z, c);
}
return c;
diff --git a/sdk/wayland.js b/sdk/wayland.js
index 3cece0f..22aff74 100644
--- a/sdk/wayland.js
+++ b/sdk/wayland.js
@@ -6,7 +6,7 @@
// el suyo (GTK) van "sin marco": args.csd = true, y el tema dibuja solo el contenido. Mover y
// cambiar el tamaño desde la barra de una app GTK llega como pedido del compositor.
import { createElement as h } from 'react';
-import { View, Text, Surface, addListener } from '@lordos/runtime';
+import { View, Text, Surface, addListener, onShellKeyboard, shellHasKeyboard } from '@lordos/runtime';
import { windows, wm, registerBuiltinApp, windowChrome, pointerWorkArea, getApp } from './windows.js';
import { useAppWindow } from './components.jsx';
import { locale, appName } from './i18n.js';
@@ -104,7 +104,8 @@ function sync() {
const list = windows.get();
const vis = list.filter((w) => !w.minimized);
const top = vis.length ? vis[vis.length - 1] : null;
- const f = top ? surfaceOf(top.id) : 0;
+ // search, the launcher, a sheet or a system prompt is open: the keys are LordOS's, not the app's
+ const f = top && !shellHasKeyboard() ? surfaceOf(top.id) : 0;
if (f !== lastFocus) { lastFocus = f; lord.wayland.focus(f); }
for (const w of list) {
const s = surfaceOf(w.id);
@@ -114,6 +115,7 @@ function sync() {
}
}
windows.subscribe(sync);
+if (typeof onShellKeyboard === 'function') onShellKeyboard(() => sync());
export const wayland = {
info: () => (typeof lord.wayland !== 'undefined' ? lord.wayland.info() : { socket: '', windows: 0 }),
diff --git a/server/tests/keyfocus/shellkeys.sh b/server/tests/keyfocus/shellkeys.sh
new file mode 100755
index 0000000..eae2941
--- /dev/null
+++ b/server/tests/keyfocus/shellkeys.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# shellkeys.sh SECONDS — does a Linux app still get the keys while LordOS's search, a sheet or a
+# system prompt is open? (0.8.2 security fix: runtime/index.js counts what is open in the overlay,
+# modal and system layers and sdk/wayland.js then gives the Wayland keyboard focus to nobody.)
+#
+# Runs tools/diag/keylag-client (a Wayland window that prints one line per wl_keyboard.key press,
+# never the key itself) for SECONDS and prints how many key presses it received. Use it inside a
+# LordOS session, with the client's window in front:
+# 1. type while the window has the keyboard → keys > 0
+# 2. open the search (or a keyring/permission prompt), type into it → keys = 0
+# 3. close it and type again → keys > 0
+# The keys can be typed by hand or sent from the host (qm sendkey / QMP). docs/PRIVACY.md.
+secs=${1:-10}
+client=${KEYLAG_CLIENT:-$(dirname "$0")/../../../tools/diag/keylag-client}
+[ -x "$client" ] || { echo "build tools/diag/keylag-client first (see its header) or set KEYLAG_CLIENT" >&2; exit 2; }
+export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/run/user/$(id -u)} WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-wayland-0}
+out=$(mktemp)
+timeout "$secs" "$client" > "$out" 2>/dev/null
+echo "keys=$(grep -c 'client key' "$out")"
+rm -f "$out"