Backport of the input-device name fix (PR #8129 by @acrogenesis, merged to
quattro as 9285b19d) 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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018DEMYa9UWtroz93DhMTtcV
79 lines
2.0 KiB
Bash
Executable File
79 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Enable, disable, toggle, or recover the internal laptop display
|
|
# omarchy:args=<on|off|toggle|recover>
|
|
|
|
TOGGLE="internal-monitor-disable"
|
|
TOGGLE_FLAG="$HOME/.local/state/omarchy/toggles/hypr/$TOGGLE.lua"
|
|
MIRROR_TOGGLE="internal-monitor-mirror"
|
|
|
|
INTERNAL=$(omarchy-hyprland-monitor-laptop)
|
|
|
|
wake() {
|
|
hyprctl dispatch 'hl.dsp.dpms({ action = "enable" })' >/dev/null 2>&1 || true
|
|
}
|
|
|
|
on() {
|
|
if omarchy-hyprland-toggle-enabled $TOGGLE; then
|
|
omarchy-hyprland-toggle $TOGGLE off
|
|
omarchy-notification-send -g "Laptop display enabled"
|
|
fi
|
|
|
|
wake
|
|
}
|
|
|
|
off() {
|
|
if [[ -z $INTERNAL ]]; then
|
|
omarchy-notification-send -g "No laptop display found"
|
|
exit 1
|
|
fi
|
|
|
|
# The name is written into generated Lua below, so only a plain connector
|
|
# name may pass; anything else could execute on the next reload.
|
|
if [[ ! $INTERNAL =~ ^[A-Za-z0-9._-]+$ ]]; then
|
|
omarchy-notification-send -g "Refusing unsafe monitor name"
|
|
exit 1
|
|
fi
|
|
|
|
if ! omarchy-hyprland-monitor-external-active; then
|
|
omarchy-notification-send -g "Can't disable the only active display"
|
|
exit 1
|
|
fi
|
|
|
|
if omarchy-hyprland-toggle-disabled $TOGGLE && omarchy-hyprland-toggle-disabled $MIRROR_TOGGLE; then
|
|
printf 'hl.monitor({ output = "%s", disabled = true })\n' "$INTERNAL" >"$TOGGLE_FLAG"
|
|
omarchy-notification-send -g "Laptop display disabled"
|
|
hyprctl reload
|
|
fi
|
|
}
|
|
|
|
recover() {
|
|
# Runs from the clamshell watcher every few seconds, so it must be a no-op
|
|
# unless it actually re-enables a display: an unconditional wake here undoes
|
|
# lock-screen blanking and races the resume modeset into a visible flash.
|
|
omarchy-hyprland-monitor-external-active && return 0
|
|
omarchy-hyprland-toggle-enabled $TOGGLE || return 0
|
|
|
|
omarchy-hyprland-toggle $TOGGLE off
|
|
wake
|
|
}
|
|
|
|
toggle() {
|
|
if omarchy-hyprland-toggle-enabled $TOGGLE; then
|
|
on
|
|
else
|
|
off
|
|
fi
|
|
}
|
|
|
|
case "$1" in
|
|
on) on ;;
|
|
off) off ;;
|
|
toggle) toggle ;;
|
|
recover) recover ;;
|
|
*)
|
|
echo "Usage: $(basename "$0") {on|off|toggle|recover}" >&2
|
|
exit 1
|
|
;;
|
|
esac
|