Skip to content

[Security] Stop USB device names from being executed as Hyprland Lua - #8129

Merged
dhh merged 3 commits into
omacom:quattrofrom
acrogenesis:harden-input-device-usb-name
Aug 25, 2026
Merged

dhh merged 3 commits into
omacom:quattrofrom
acrogenesis:harden-input-device-usb-name

Conversation

@acrogenesis

@acrogenesis acrogenesis commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

A HID gadget can put an arbitrary string in the USB product/device name Hyprland reports. omarchy-toggle-input-device interpolated that name into hyprctl eval and into a generated Lua file under ~/.local/state/omarchy/toggles/hypr/, which Hyprland sources on every start.

XF86TouchpadToggle (HID F21) is bound with locked = true, so this runs on a locked session as the logged-in user. Disable persists after the gadget is unplugged. Not network RCE and not root by itself; High for an evil-maid / malicious-USB take of the user account.

Public report: Omarchy Exploit (Jorrit Jongma / Chainfire).

Fix

The disable is no longer executable Lua anywhere. The device name is stored as plain-text data in a *-disabled-name sidecar and read back by a packaged module (default/hypr/disabled-input-device.lua) on every reload; the live hyprctl eval Lua-quotes the name and rejects control characters outright. The old generated-Lua templates are dropped entirely — so nothing can seed a disabled state to /etc/skel — leaving the sidecar, read from a hardcoded ~/.local/state to match the sibling toggle tools, as the single source of truth.

A migration recovers the device name from any already-generated toggle Lua and deletes the file, sanitizing installs that already ran the vulnerable version.

Same class, hardened alongside

Reviewing the fix surfaced the identical "hyprctl name → Lua" pattern in the monitor helpers. All four scripts that write an output name into Lua — omarchy-hyprland-monitor-internal, -internal-mirror, -clamshell, and -scaling — now validate it against a plain-connector-name pattern before it can be written as code. Real connector names (eDP-1, DP-3, …) are unaffected; a user-created headless output carrying an arbitrary name is rejected. paths.lua also now treats a set-but-empty XDG_STATE_HOME as unset, matching the bash side so state is never read from the filesystem root.

Tests

  • test/shell.d/toggle-input-device-test.sh — Lua-quoting, data-only persistence, the public PoC string, migration recovery of real names, and the wedge / idempotence paths.
  • test/shell.d/monitor-output-name-test.sh — each monitor script accepts a real connector and rejects a metacharacter-laced name.
  • test/shell.d/hyprland-paths-test.sh — empty vs set XDG variables.

@acrogenesis
acrogenesis force-pushed the harden-input-device-usb-name branch 2 times, most recently from bc3794a to bef7ee6 Compare August 25, 2026 05:04
@acrogenesis
acrogenesis marked this pull request as ready for review August 25, 2026 05:35
Copilot AI balanced review requested due to automatic review settings August 25, 2026 05:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Replaces executable input-device toggle state with plain data and hardens monitor-name interpolation against Lua injection.

Changes:

  • Adds data-only device persistence and migration cleanup.
  • Validates monitor connector names before Lua interpolation.
  • Adds security, migration, and XDG-path tests.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 8 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
bin/omarchy-toggle-input-device Safely quotes and persists device names.
bin/omarchy-hyprland-monitor-clamshell Validates internal monitor names.
bin/omarchy-hyprland-monitor-internal Validates generated monitor state.
bin/omarchy-hyprland-monitor-internal-mirror Validates mirror output names.
bin/omarchy-hyprland-monitor-scaling Validates focused output names.
default/hypr/disabled-input-device.lua Loads disabled-device names as data.
default/hypr/paths.lua Handles empty XDG variables.
default/hypr/toggles.lua Applies persisted device disables.
manual/13-toggles-idle-screensaver.md Documents data-based persistence.
migrations/1787618700.sh Migrates legacy generated Lua state.
test/shell.d/hyprland-paths-test.sh Tests XDG path behavior.
test/shell.d/monitor-output-name-test.sh Tests monitor-name validation.
test/shell.d/toggle-input-device-test.sh Tests injection prevention and migration.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread default/hypr/toggles.lua Resolved
Hyprland input-device and monitor names come from USB descriptors and
hyprctl output, so they are attacker-influenceable, yet the toggle and
monitor commands interpolated them straight into hyprctl eval and into
generated Lua that Hyprland re-executes on every reload. The input-device
toggle keys are bound with locked = true, so a malicious USB name reached
Lua code execution from the lock screen; a persisted disable made it run
on every start. This closes that class everywhere it appeared.

- The touchpad/touchscreen disable is now the device name in a plain-text
  sidecar file, read back by a packaged Lua module on reload, never a
  generated Lua file. hyprctl eval Lua-quotes the name and control
  characters are rejected outright.
- Dropped the shipped *-disabled.lua templates so nothing seeds a
  disabled state to /etc/skel, making the name file the single source of
  truth read from a hardcoded ~/.local/state to match the sibling tools.
- The reload loader excludes those two legacy filenames, so a leftover
  generated *-disabled.lua on a not-yet-migrated install can never be
  sourced as code again; a migration then recovers the device name from
  it and deletes it, sanitizing installs that ran the vulnerable version.
- All four monitor scripts (internal, mirror, clamshell, scaling) now
  validate an output name against a plain-connector-name pattern before
  writing it as Lua, closing the same latent pattern in the siblings.
- paths.lua treats a set-but-empty XDG_STATE_HOME as unset, matching the
  bash side so state is never read from the filesystem root.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0144ZDt44vtxjyF8j9Y88NrM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 14 changed files in this pull request and generated no new comments.

@Chainfire

Copy link
Copy Markdown

Notes:

XF86TouchpadOn (HID F22) also triggers the immediate path, though not the persistent LUA path.

XF86TouchpadOff (HID F23) does nothing (seemingly remapped to actual F23).

HID Ctrl+Super+F24 should also take the HID F21 (XF86TouchpadToggle) path, both immediate trigger and persistent LUA, according to Claude but I was not able to reproduce it.

lua discards the status of a chunk read from stdin, so a blown assert printed its traceback and still exited 0: the surrounding `set -euo pipefail` never fired and the following `pass` printed `ok`. Every Lua block in these two files was unenforced, including the assertion that a quoted `hyprctl eval` cannot reach `os.execute` and the negative control that proves the test can detect the injection at all. Passing the chunk as a script argument makes lua report the failure.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at a73351a8, with an independent second opinion from Codex at xhigh effort.

The injection fix holds up. Neither of us found an input that escapes the new Lua literal: backslashes are doubled before quotes are escaped, so \ddd, \x, \z, \u{...} and trailing backslashes all stay data, and real newlines are rejected by the [[:cntrl:]] guard before quoting ever happens. require_device dominates every sink, the require_all exclusion keeps a leftover payload from running in the window before the migration, the recovery regex parses as intended ([:cntrl:] really is the POSIX class inside that bracket expression, not a literal set), and the new module genuinely re-runs on every reload because bootstrap.lua clears package.loaded for default.hypr.*. The only consumers of hyprctl devices are the two omarchy-hw-* helpers, and both are covered.

Pushed one fix, 6b8caa0. Every lua <<'LUA' block in the new tests was a dead assertion. lua discards the status of a chunk read from stdin, so a blown assert printed its traceback and still exited 0 — the surrounding set -euo pipefail never fired and the following pass printed ok. That left 18 assertions unenforced, including the one that matters most here, "quoted hyprctl eval must not run os.execute", and the negative control that is supposed to prove the test can detect the injection at all. The demonstration is that test/shell.d/hyprland-paths-test.sh printed ok for both of its assertions and exited 0 against a default/hypr/paths.lua I had replaced with entirely wrong values. The fix is lua to lua - in four places; your tests still pass unchanged on real source, and now they fail when the fix is broken on purpose.

One thing left for you. A user who had their touchpad or touchscreen disabled gets it back enabled for the rest of the session after an update. The pacman PostTransaction hook in default/libalpm/hooks/90-omarchy-hyprland-reload-resume.hook runs omarchy-hyprland-reload-guard resume, which reloads Hyprland during omarchy-update-system-pkgs — before omarchy-migrate runs at bin/omarchy-update:47-48. At that reload the legacy Lua is correctly excluded but <kind>-disabled-name does not exist yet, so nothing disables the device; the migration then writes the sidecar without re-applying it, and the disable stays lost until the next reload or login. Not executing the payload is the right call, so the gap is only that the migration never re-applies the disable it just recovered. This one was Codex's find, and I confirmed it end to end. How much a migration should reach into a live session is a design call, so I left it to you rather than pushing an answer.

Same class, but not this PR's job. bin/omarchy-launch-screensaver:25 still interpolates a raw name from hyprctl monitors -j into hl.dsp.focus({ monitor = "..." }), fed from the loop at line 52. It is not reachable from the USB threat — creating a headless output with an arbitrary name already requires Hyprland IPC access — and it is live-eval only, never persisted. Worth its own change rather than growing this one.

Tests. ./test/cli clean, ./test/shell 2484 assertions passing, re-run after my commit rather than before it. Four files fail — config, network-qr, snapper, unowned-system-paths — identically on the base commit; they want a sibling omarchy-pkgs checkout, so they are environmental rather than yours. These ran in a local sandbox rather than a disposable worker, so they are evidence rather than proof. I also mutation-tested eleven ways: all four monitor guards, the eval quoting, the control-character guard, the require_all exclusion and the migration filter are each genuinely covered by a test that fails when you break them.

Both earlier Copilot comments were valid against bef7ee67, and you have already addressed them in a73351a8.

Last thing worth knowing: #7898 is a competing fix for the same vulnerability, and #8145 rewrites bin/omarchy-hyprland-monitor-scaling and will conflict with the guard added here. Which of those lands is the maintainer's call, not something this review settles.

The package hook reloads Hyprland during `omarchy-update-system-pkgs`, before `omarchy-migrate` runs, and at that reload the generated Lua is already excluded while the name file does not exist yet — so a touchpad or touchscreen the user had switched off comes back on, and stays on until their next login. Reload once more once the name has been recovered, which is the same path a login already takes to read it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Pushed 86bdd3c9, which closes the migration gap from my last comment, and re-verified the whole change on a disposable worker VM running a real Hyprland session rather than in a local sandbox.

The fix. The migration now reloads once after it has recovered the device name, so a disable the user had set survives the update instead of waiting for their next login. It reloads only when there is a name file to re-apply, and it goes through hyprctl reload rather than issuing its own hl.device eval — that way the disable is applied by the same path a login already uses, and the Lua quoting is not copied into a second place where it could drift from apply_device. migrations/1784767406.sh is the precedent for a migration reloading Hyprland.

Verified against a real compositor. The part worth reporting is the negative control: with the loader from quattro and a leftover touchpad-disabled.lua carrying hl.device({ name = "trackpad"})os.execute("touch /tmp/PWNED")--", enabled = false }), a plain hyprctl reload created /tmp/PWNED. On the same VM with your loader, the same file does not execute. The require_all exclusion holds where it actually matters, not just in a stubbed harness. I also traced the migration's hyprctl calls through a shim: exactly one reload, and only when something needs re-applying.

One limit worth stating plainly. Hyprland exposes no readback for a device's enabled state — hyprctl devices carries no such field, getoption has no such option, and an hl.device rule naming a device that does not exist is accepted silently with no config error. So the last link, that disabled-input-device.lua reaches hl.device inside the compositor rather than inside a real lua interpreter with the real bootstrap, is asserted at the Lua level and is not observable through hyprctl. Everything on either side of it is verified live. I looked for an observable and did not find one; if you know of one I will go back and close it.

Tests. ./test/cli clean. ./test/shell on the worker's real session: 198 of 201 files pass. ascii-test.sh, branding-about-animation-test.sh and screenshot-sanity-test.sh fail, and I ran those three against b86d4505 on the same VM where they fail identically — software rendering in the VM, not anything here. The two new assertions are mutation-tested both ways: dropping the reload fails the run, and reloading when there is nothing to migrate fails it too.

Codex at xhigh found this defect, so it is co-authored on the commit.

Nothing further is open against this PR from my side. The bin/omarchy-launch-screensaver:25 sink and the #7898 / #8145 overlap from my previous comment are unchanged, and both are the maintainer's call rather than yours.

@rick

rick commented Aug 25, 2026

Copy link
Copy Markdown
fuckin sexy

lgtm

@rick rick left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@dhh
dhh merged commit 9285b19 into omacom:quattro Aug 25, 2026
omarchybot pushed a commit that referenced this pull request Aug 25, 2026
…(backport of #8129)

Backport of the input-device name fix (PR #8129 by @acrogenesis, merged to
quattro as 9285b19) onto the v4-0-1 release branch.

Hyprland input-device and monitor names come from USB descriptors and hyprctl
output, so they are attacker-influenceable, yet the toggle and monitor commands
interpolated them straight into hyprctl eval and into generated Lua that
Hyprland re-executes on every reload. XF86TouchpadToggle is bound with
locked = true, so a malicious USB name reached Lua execution from the lock
screen as the logged-in user, and a persisted disable made it run on every
start. Publicly reported by Jorrit Jongma / Chainfire.

The disable is no longer executable Lua anywhere. The device name is stored as
plain-text data in a *-disabled-name sidecar and read back by a packaged module,
default/hypr/disabled-input-device.lua, on every reload; the live hyprctl eval
Lua-quotes the name and rejects control characters outright. The reload loader
excludes the two legacy filenames, so a leftover generated *-disabled.lua on a
not-yet-migrated install can never be sourced as code again, and a migration
recovers the device name from it and deletes it, sanitizing installs that ran
the vulnerable version. All four monitor scripts validate an output name against
a plain-connector-name pattern before writing it as Lua, closing the same latent
pattern in the siblings, and paths.lua treats a set-but-empty XDG_STATE_HOME as
unset to match the bash side.

Clean cherry-pick: all fourteen files are byte-identical to quattro, so merging
v4-0-1 into quattro resolves without a conflict. This branch ships no leftover
*-disabled.lua template of its own -- the tracked "disabled" files are the same
two quattro has -- so the migration is the only path that has to sanitize
anything here.

test/shell passes: 192 files, including the three this adds. The toggle suite's
public-PoC case passes here, as do the monitor scripts' accept/reject cases and
the XDG path cases. test/cli passes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_018DEMYa9UWtroz93DhMTtcV
@omarchybot omarchybot mentioned this pull request Aug 25, 2026
@acrogenesis
acrogenesis deleted the harden-input-device-usb-name branch August 25, 2026 17:36
Roriz added a commit to Roriz/omarchy that referenced this pull request Sep 7, 2026
Extend the coverage added in the previous commit with the edge cases
worth nailing down before this touches a live desktop's monitor state:

- Negative coordinates round-trip (a monitor above/left of the origin).
- A corrupted or injection-crafted position state file is validated on
  read and never forwarded into the generated hyprctl eval string,
  mirroring the omacom#8129 hardening for the internal connector name.
- A non-integer reported position is never remembered in the first
  place.
- A manual internal-monitor disable keeps the clamshell layer from
  touching scale or position at all.
- A poll tick re-running disable_internal while already docked does
  not clobber the remembered value with a disabled panel's empty read.
- Two successive dock/undock cycles track a rearranged position
  without leaking a stale one from the first cycle.
- A live scale-drift correction (panel never disabled) carries the
  remembered position instead of slipping back to "auto".
- A configured position variable reference, and the catch-all rule's
  own position, are both confirmed against precedence: a rule specific
  to the internal output wins, a remembered value beats the catch-all,
  and the catch-all's position is never read for the internal panel.

Also made the hyprctl stub list an external monitor alongside the
internal one, like real `hyprctl monitors all -j` output, so every
case in the file exercises the by-name jq selection instead of a
single-monitor array that could never expose a selection bug.

Verified these fail without the previous commit's fix (reverted the
script only, kept the new tests: fails immediately on "clamshell
disable remembers internal position").

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BHyQocSji8JUDRNaaQsK7M
Roriz added a commit to Roriz/omarchy that referenced this pull request Sep 7, 2026
Extend the coverage added in the previous commit with the edge cases
worth nailing down before this touches a live desktop's monitor state:

- Negative coordinates round-trip (a monitor above/left of the origin).
- A corrupted or injection-crafted position state file is validated on
  read and never forwarded into the generated hyprctl eval string,
  mirroring the omacom#8129 hardening for the internal connector name.
- A non-integer reported position is never remembered in the first
  place.
- A manual internal-monitor disable keeps the clamshell layer from
  touching scale or position at all.
- A poll tick re-running disable_internal while already docked does
  not clobber the remembered value with a disabled panel's empty read.
- Two successive dock/undock cycles track a rearranged position
  without leaking a stale one from the first cycle.
- A live scale-drift correction (panel never disabled) carries the
  remembered position instead of slipping back to "auto".
- A configured position variable reference, and the catch-all rule's
  own position, are both confirmed against precedence: a rule specific
  to the internal output wins, a remembered value beats the catch-all,
  and the catch-all's position is never read for the internal panel.

Also made the hyprctl stub list an external monitor alongside the
internal one, like real `hyprctl monitors all -j` output, so every
case in the file exercises the by-name jq selection instead of a
single-monitor array that could never expose a selection bug.

Verified these fail without the previous commit's fix (reverted the
script only, kept the new tests: fails immediately on "clamshell
disable remembers internal position").

Co-Authored-By: Claude Opus 5 <[email protected]>
nick1udwig pushed a commit to nick1udwig/omarchy that referenced this pull request Sep 9, 2026
…macom#8129)

* Stop device names from being executed as Hyprland Lua

Hyprland input-device and monitor names come from USB descriptors and
hyprctl output, so they are attacker-influenceable, yet the toggle and
monitor commands interpolated them straight into hyprctl eval and into
generated Lua that Hyprland re-executes on every reload. The input-device
toggle keys are bound with locked = true, so a malicious USB name reached
Lua code execution from the lock screen; a persisted disable made it run
on every start. This closes that class everywhere it appeared.

- The touchpad/touchscreen disable is now the device name in a plain-text
  sidecar file, read back by a packaged Lua module on reload, never a
  generated Lua file. hyprctl eval Lua-quotes the name and control
  characters are rejected outright.
- Dropped the shipped *-disabled.lua templates so nothing seeds a
  disabled state to /etc/skel, making the name file the single source of
  truth read from a hardcoded ~/.local/state to match the sibling tools.
- The reload loader excludes those two legacy filenames, so a leftover
  generated *-disabled.lua on a not-yet-migrated install can never be
  sourced as code again; a migration then recovers the device name from
  it and deletes it, sanitizing installs that ran the vulnerable version.
- All four monitor scripts (internal, mirror, clamshell, scaling) now
  validate an output name against a plain-connector-name pattern before
  writing it as Lua, closing the same latent pattern in the siblings.
- paths.lua treats a set-but-empty XDG_STATE_HOME as unset, matching the
  bash side so state is never read from the filesystem root.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0144ZDt44vtxjyF8j9Y88NrM

* Let a failing Lua assertion fail the test

lua discards the status of a chunk read from stdin, so a blown assert printed its traceback and still exited 0: the surrounding `set -euo pipefail` never fired and the following `pass` printed `ok`. Every Lua block in these two files was unenforced, including the assertion that a quoted `hyprctl eval` cannot reach `os.execute` and the negative control that proves the test can detect the injection at all. Passing the chunk as a script argument makes lua report the failure.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Re-apply a recovered input-device disable to the running session

The package hook reloads Hyprland during `omarchy-update-system-pkgs`, before `omarchy-migrate` runs, and at that reload the generated Lua is already excluded while the name file does not exist yet — so a touchpad or touchscreen the user had switched off comes back on, and stays on until their next login. Reload once more once the name has been recovered, which is the same path a login already takes to read it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Co-authored-by: Omarchybot <[email protected]>
Co-authored-by: Codex XHigh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants