Skip to content

Quote input device names before embedding them in Lua - #7898

Closed
dhh wants to merge 1 commit into
quattrofrom
fix/input-device-lua-injection
Closed

dhh wants to merge 1 commit into
quattrofrom
fix/input-device-lua-injection

Conversation

@dhh

@dhh dhh commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Touchpad and touchscreen names come from the peripheral's own USB string descriptors, so they are attacker-controlled data: a malicious or compromised device can report a name containing a double quote. omarchy-toggle-input-device embedded that name unescaped into two Lua string literals — the live hyprctl eval "hl.device({ name = \"$device\", ... })" call and the persisted toggle state file under ~/.local/state/omarchy/toggles/hypr/, which Hyprland sources on every config reload. A crafted device name could therefore execute arbitrary Lua as the session user, immediately and persistently across restarts.

The fix adds a small omarchy-lua-quote helper that escapes the only characters able to break out of or corrupt a double-quoted Lua literal — backslash first so the later escapes stay literal, then double quote, then raw newline and carriage return, which Lua rejects inside a short literal — and leaves every other byte untouched, so the quoted name still matches what Hyprland reports. omarchy-toggle-input-device quotes the name once and uses the quoted form for both sinks. New test/cli cases pin the behavior against a plain device name, embedded quotes, backslashes, newlines, carriage returns, and a full breakout payload, and the quoted output was verified against Lua 5.4 to parse as a pure string literal and round-trip byte-for-byte.

Reviewed by Codex at xhigh effort: it round-tripped every non-NUL byte through Lua 5.4 and 5.5 against both sink expressions and found no exploitable defect or regression; the carriage-return test case its review prompted is part of the change.

🤖 Generated by Kimi K3 in OpenCode. Reviewed by Codex XHigh.

Touchpad and touchscreen names come from the peripheral's own USB descriptors, so a device whose name contains a double quote could break out of the Lua string literal in omarchy-toggle-input-device: both the live hyprctl eval and the persisted toggle state file that Hyprland sources on every config reload. That turned a malicious or compromised peripheral into arbitrary Lua execution as the session user, persistent across restarts.

Add omarchy-lua-quote, which escapes the only characters that can break out of or corrupt a double-quoted Lua literal (backslash, double quote, raw newline, carriage return) while leaving the name byte-for-byte intact so it still matches what Hyprland reports, and use it for both sinks.

🤖 Generated by Kimi K3 in OpenCode. Reviewed by Codex XHigh.

Co-authored-by: Codex XHigh <[email protected]>
Copilot AI balanced review requested due to automatic review settings August 23, 2026 14:32

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

Escapes attacker-controlled input device names before embedding them in live and persisted Lua expressions.

Changes:

  • Adds a Lua string-escaping helper.
  • Uses escaped names in both toggle paths.
  • Adds escaping tests for hostile characters.

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 1 out of 3 changed files in this pull request and generated 1 comment.

File Description
bin/omarchy-lua-quote Adds Lua literal escaping.
bin/omarchy-toggle-input-device Escapes device names before Lua interpolation.
test/cli Tests escaping behavior and injection payloads.

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

Comment thread test/cli
Comment on lines +811 to +814
# USB device names are peripheral-controlled and land inside double-quoted Lua
# string literals (hyprctl eval, persisted toggle state files), so the quoting
# helper must keep hostile names inside the literal.
output=$(omarchy-lua-quote 'ELAN1200:00 04F3:30BA Touchpad')
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed against quattro at d468ee2. The bug was real at this branch's fork point and the escaping here is correct, but quattro already fixes it, more thoroughly, in #8129 (9285b19), so I recommend closing this as superseded.

What quattro has now:

  • bin/omarchy-toggle-input-device rejects device names with control characters outright and escapes backslashes and double quotes before the live hyprctl eval.
  • The persisted disable is no longer generated Lua: the name is written as plain data to ~/.local/state/omarchy/toggles/hypr/<kind>-disabled-name and read back by default/hypr/disabled-input-device.lua, which passes it to hl.device as a value, so there is no literal left to break out of on reload.
  • default/hypr/toggles.lua skips the legacy *-disabled.lua files and migrations/1787618700.sh recovers the name from them and deletes them, which also cleans up a malicious state file written before the upgrade. This branch would not have done that.
  • test/shell.d/toggle-input-device-test.sh covers injection through eval, through reload, and through a leftover legacy file.

Nothing in this pull request is missing from quattro that matters to a user. It also conflicts with quattro in bin/omarchy-toggle-input-device, and resolving the conflict toward this branch would bring back the generated-Lua state file. No worker was used: there is nothing left to verify that quattro does not already carry.

Checked by Claude Opus 5.5 and by Codex Medium as a second opinion; Codex reached the same conclusion, with independence from this review not guaranteed. Waiting on the maintainer to close it.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thank you for this, @dhh. quattro already fixes this (#8129), so it is closed as superseded.

Closed at the maintainer's request. The review comment above has the details; it was done by Claude Opus 5.5 with Codex Medium as a second opinion, whose agreement is not independent.

@omarchybot omarchybot closed this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants