Repository navigation
Why Toshy Runs As Your User
A question that comes up periodically: isn't it a security problem that Toshy runs as your own user, with your account granted access to input devices? Shouldn't the keymapper run as root, or better yet, as a separate limited-privilege user, so your account doesn't need raw input access?
Short answer: running as root is worse in every way, and running as a separate limited user turns out to provide almost no real security benefit while making the project dramatically harder to install, debug, and maintain. This article explains why.
Toshy grew out of Kinto.sh, which uses the xkeysnail keymapper. That stack
runs the keymapper entirely as root, and works only in X11, where a root
process can be given access to the display to read the active window context
(needed for app-specific keymapping). Kinto is still in use today by plenty
of people on X11 sessions, and works fine there — the root-based design just
has no path forward on Wayland.
That approach is a dead end on Wayland. Wayland compositors deliberately do not hand out window context to arbitrary outside processes, and especially not to random root daemons. The only practical ways to get the active window's app class and title on Wayland involve components running inside your desktop session: a KWin script, a wlroots protocol listener, a shell extension, and so on. Those session components then need to hand that info to the keymapper, quickly and constantly.
Running everything as the logged-in user makes that trivial: the keymapper
just joins your session D-Bus and asks the helper for the current window
context. Access to the input devices themselves is granted through membership
in the input group and/or udev rules. That's the current design, and it
performs well even on old hardware.
Also worth stating plainly: running as your user is already a large security improvement over the root-based approach. A bug in a root keymapper is a system-wide compromise. A bug in a user process is not.
The suggestion is usually something like this: create a dedicated
keymapper system user, give only that user access to the input devices,
and have it receive window context from a small daemon in your session. Your
own account then never touches /dev/input directly.
It sounds like textbook privilege separation. The problem is that when you look at what a keymapper actually is and does, the privilege boundary turns out to be imaginary. It leaks in both directions.
The Toshy config file is not a settings file. It is Python code, executed by the keymapper, and that's by design — it's what makes the deep customization possible (custom functions, conditional logic, per-app behavior, and so on). The config is, quite literally, part of the program.
Now imagine the keymapper runs as a separate privileged user but still loads the config file out of your home folder. Anything running as you — say, malware that has compromised your account — can simply edit that config file and wait for the keymapper to restart. At that point the malicious code is running inside the "protected" process, with full input device access. The separate user protected nothing.
Closing that hole would require making the config unwritable by you (root-owned, password-gated edits — which makes normal editing miserable), or replacing the Python config with a locked-down declarative format that gets validated before loading. The second option would mean throwing away the entire config system and most of what makes Toshy flexible.
Flip it around. Suppose the keymapper process itself were somehow compromised (through what attack surface is unclear — it parses kernel input events, a very small and boring input — but suppose). Would the separate user contain the damage?
No. The keymapper's job requires the ability to synthesize arbitrary
keystrokes into your session via uinput. A process that can type anything
into your active session can open a terminal and type commands as you. So a
compromised "limited" keymapper user escalates right back into full control
of your account anyway.
Total, bidirectional access to the input stream is not an unfortunate side effect of a keymapper. It is the product. There is no way to least-privilege your way around the thing the software exists to do. The two leaks together mean the elaborate airlock has both doors propped open.
Even if the security benefit were real, here's what the split-user design would actually require:
- New cross-user IPC for window context. A separate user cannot access your session D-Bus (the socket lives in your private runtime directory), so all of the existing context plumbing would need to be replaced with shared sockets or system-bus services, with correct permissions maintained across installs and upgrades.
- Passwordless service control. Today, restarting Toshy is a one-click, no-password action because the services are your services. A system-level keymapper would need polkit rules to allow that, and polkit rule formats and behavior vary across distros and versions. Getting that reliable across everything Toshy supports would be a large project all by itself — and a new root-required phase in the installer.
- Session and seat tracking. Today the keymapper naturally lives and dies with your session. A system-level keymapper would have to track which session is active, handle fast user switching, and decide whose config to load when multiple users exist. That's a whole subsystem that currently doesn't need to exist.
- A much worse debugging story. Right now,
toshy-debugruns the config in your own terminal, in the same environment as the service. Under a split user, a faithful debug session would require running as the other user (sudo, or more polkit machinery), and an unfaithful one would run in a different environment than the real service — the classic recipe for bugs that only appear in the service and can't be reproduced in debug mode. - Non-systemd systems. Toshy supports distros without systemd. Every piece of the above would need parallel solutions for other init systems.
All of that cost, for a security boundary that Leak #1 and Leak #2 show to be mostly theater.
The honest security posture is this: any keymapper, by definition, can see
and synthesize every keystroke. That is true of Toshy, of every other
evdev-based remapper, and of your compositor itself. Toshy runs as your user,
not root, which already limits a worst-case failure to your account rather
than the whole system. The config is code you control, in your own home
folder — and in that respect it's nothing unusual. Your home folder is
already full of files that any process running as you can rewrite, and that
will then execute code or reshape your session with your privileges: your
shell profile (.bashrc, .zshrc) runs arbitrary code every time you open a
terminal; anything dropped into ~/.config/autostart/ launches automatically
at every login; a unit placed in ~/.config/systemd/user/ becomes a
persistent service under your account; and files in
~/.config/environment.d/ quietly alter the environment of everything in
your systemd user session. A malicious process running in your user space
already has all of these doors. The Toshy config file doesn't open a new one
— it's just one more file in a home directory that was never a security
boundary against your own account in the first place.
Longer term, the "right" architecture for this whole problem class is being built upstream: compositor-mediated input via libei and the InputCapture portal, where the compositor itself grants and supervises input access. When that ecosystem matures across desktop environments, it will be worth revisiting. Until then, bolting a fake privilege boundary onto the current design would make Toshy harder to install, harder to debug, and harder to maintain, without making anyone meaningfully safer.