Repository navigation
[Security] Stop USB device names from being executed as Hyprland Lua #8129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| -- Disable a Hyprland input device whose name was stored as data, not Lua. | ||
| -- Device names come from USB descriptors and must never be loaded as code. | ||
|
|
||
| local paths = require("default.hypr.paths") | ||
|
|
||
| return function(kind) | ||
| -- Hardcoded to ~/.local/state to match omarchy-toggle-input-device and the | ||
| -- sibling bash toggle tools, which all write there regardless of | ||
| -- XDG_STATE_HOME. | ||
| local file = io.open(paths.home .. "/.local/state/omarchy/toggles/hypr/" .. kind .. "-disabled-name", "r") | ||
| if not file then | ||
| return | ||
| end | ||
|
|
||
| local name = file:read("*l") | ||
| file:close() | ||
|
|
||
| if name and name ~= "" then | ||
| hl.device({ name = name, enabled = false }) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| echo "Store Hyprland input-device names as data instead of generated Lua" | ||
|
|
||
| # omarchy-toggle-input-device used to interpolate hyprctl device names into | ||
| # hyprctl eval and a generated Lua file. Those names come from USB descriptors, | ||
| # so recover the plain device name as data and delete the generated Lua. A name | ||
| # that could have broken out of the old Lua string literal is discarded, not | ||
| # trusted. The old script wrote to ~/.local/state regardless of XDG_STATE_HOME. | ||
| toggles_dir="$HOME/.local/state/omarchy/toggles/hypr" | ||
|
|
||
| reapply=0 | ||
|
|
||
| for kind in touchpad touchscreen; do | ||
| state_file="$toggles_dir/$kind-disabled.lua" | ||
| name_file="$toggles_dir/$kind-disabled-name" | ||
|
|
||
| [[ -f $state_file ]] || continue | ||
|
|
||
| if [[ ! -f $name_file && -r $state_file ]]; then | ||
| old=$(<"$state_file") | ||
| pattern='^hl\.device\(\{ name = "([^"\\[:cntrl:]]+)", enabled = false \}\)$' | ||
| if [[ $old =~ $pattern ]]; then | ||
| printf '%s\n' "${BASH_REMATCH[1]}" >"$name_file" | ||
| fi | ||
| fi | ||
|
|
||
| rm -f "$state_file" | ||
|
|
||
| if [[ -f $name_file ]]; then | ||
| reapply=1 | ||
| fi | ||
| done | ||
|
|
||
| # The package hook reloads Hyprland before migrations run, so this session has | ||
| # already dropped the disable: the generated Lua is no longer loaded and the | ||
| # name file did not exist yet to replace it. Reload once more now that it does, | ||
| # or the device the user switched off stays on until their next login. | ||
| if (( reapply )); then | ||
| hyprctl reload >/dev/null 2>&1 || true | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| require_command lua | ||
|
|
||
| run_paths() { | ||
| lua - <<'LUA' | ||
| package.path = os.getenv("OMARCHY_PATH") .. "/?.lua;" .. package.path | ||
| local paths = require("default.hypr.paths") | ||
| assert(paths.config_home == os.getenv("EXPECTED_CONFIG"), "config_home: " .. paths.config_home) | ||
| assert(paths.state_home == os.getenv("EXPECTED_STATE"), "state_home: " .. paths.state_home) | ||
| LUA | ||
| } | ||
|
|
||
| HOME="/home/test-user" OMARCHY_PATH="$ROOT" \ | ||
| XDG_CONFIG_HOME= XDG_STATE_HOME= \ | ||
| EXPECTED_CONFIG="/home/test-user/.config" EXPECTED_STATE="/home/test-user/.local/state" \ | ||
| run_paths | ||
| pass "empty XDG path variables fall back to their defaults" | ||
|
|
||
| HOME="/home/test-user" OMARCHY_PATH="$ROOT" \ | ||
| XDG_CONFIG_HOME="/custom/config" XDG_STATE_HOME="/custom/state" \ | ||
| EXPECTED_CONFIG="/custom/config" EXPECTED_STATE="/custom/state" \ | ||
| run_paths | ||
| pass "set XDG path variables are honored" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.