Skip to content

launch-screensaver: reject unsafe monitor and workspace names on 4.5 - #18008

Closed
knklinux wants to merge 3 commits into
omacom:v4-5-1from
knklinux:fix/launch-screensaver-monitor-guard-v451
Closed

knklinux wants to merge 3 commits into
omacom:v4-5-1from
knklinux:fix/launch-screensaver-monitor-guard-v451

Conversation

@knklinux

@knklinux knklinux commented Nov 7, 2026 •

Copy link
Copy Markdown

What changes

On the 4.5 branch, omarchy-launch-screensaver still pastes the monitor name and the special-workspace name straight into the Lua expression it hands to hyprctl:

hyprctl dispatch "hl.dsp.focus({ monitor = \"$1\" })" ...
hyprctl dispatch "hl.dsp.exec_cmd([[[workspace $workspace] $command]]])" ...

Both values come from hyprctl monitors -j. A name that is not a plain connector string closes the Lua string early, and this launcher has no validation, while the three monitor toggles next to it (omarchy-hyprland-monitor-clamshell, -scaling, -internal) gate the same names behind ^[A-Za-z0-9._-]+$.

quattro no longer has this code: fdbe182d3 replaced the terminal launcher with the native omarchy-screensaver overlay and deleted test/shell.d/screensaver-workspace-test.sh. The 4.5 branch still uses the terminal launcher, so this backports the guards and their regression coverage there.

  • require_safe_monitor_name and require_safe_workspace_name, fail closed, in front of hypr_focus_monitor and hypr_exec.
  • The monitor guard is the same ^[A-Za-z0-9._-]+$ and the same if / echo ... >&2 / exit 1 shape the sibling toggles use.
  • The workspace guard rejects an empty name, [, ], ; and control characters, while allowing real special names such as special:my stuff.
  • Every monitor and workspace name is validated in a pass before any focus change or terminal launch, so a rejection cannot leave an earlier screen on the wrong monitor.
  • The focused monitor name used for the close-time restore goes through the same monitor guard.
  • test/shell.d/screensaver-workspace-test.sh reads the monitor list from a monitors.json fixture so a payload travels through the same jq pipeline the real script uses, and asserts the launcher refuses it instead of dispatching it.

Verification

test/shell.d/screensaver-workspace-test.sh

12 ok, exit 0 on the 4.5 branch, with real jq, lua and socat; hyprctl and the terminal are stubbed, as in the existing test. An empty focused monitor no longer dispatches a focus, and a name with a space or a newline is rejected instead of split. Not checked: a live compositor.

Screenshots

No visible change: the launcher runs the same with a valid monitor name.

Backport the launcher guards and regression coverage from omacom#14421 to the
4.5 maintenance branch, where the terminal launcher is still in use.
@greptile-apps

greptile-apps Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR checks monitor and workspace names before using them in Hyprland commands.

  • The screensaver launcher checks names before it moves focus or opens windows.
  • The launcher skips focus restore when no monitor is focused.

The earlier whitespace-name finding is addressed by the NUL-separated read loop. No new actionable issues were found.

Reviews (3) · Last reviewed commit: "launch-screensaver: hand focus back only..." · Reviewed by Greptile

Comment thread bin/omarchy-launch-screensaver Resolved
…them

A monitor and its special workspace shared one space-separated line, so a
headless output named "DP-1 extra" became a valid monitor and a valid
workspace, both guards passed, and the launcher targeted the wrong one. A
newline in the name split the record the same way. Read each field from its
JSON record on its own, NUL between them, so a name arrives whole.
A compositor mid hotplug can report no focused monitor, and the close-time
restore then refused the empty name with exit 1 after every screensaver had
already opened. Skip the restore when the name is empty; a name that is there
is still checked before it reaches the Lua dispatch.
@knklinux

knklinux commented Nov 7, 2026

Copy link
Copy Markdown
Author

Both review points are covered on 10368d3bd:

  • P2, whitespace names — 666418c19 reads each monitor name from the
    hyprctl monitors all -j fields instead of flattening the output into words.
    A headless output named DP-1 extra now stays one value and fails the
    connector-name guard, rather than being split into a valid monitor and
    workspace. The test exercises a space and a newline in both names.
  • Empty focused monitor — 10368d3bd makes hypr_restore_focus return
    early when no monitor had focus ([[ -n $focused ]] || return 0), so the
    launcher no longer dispatches a focus with an empty name. The test drives
    FOCUSED_NAME='' and the hyprctl stub uses ${FOCUSED_NAME-DP-1}, so an
    empty name cannot stand in for an unset one.

The name guards themselves are from 035904e65. Verified on this branch:
test/shell.d/screensaver-workspace-test.sh (15 ok) and ./test/cli
(128 ok, 0 not ok).

@ryanrhughes

Copy link
Copy Markdown
Collaborator

Thanks for this! We ended up bringing 4.6's native screensaver to 4.5.1 in #19068 instead, so both release lines run the same one. The new omarchy-launch-screensaver just hands off to the binary and never puts monitor or workspace names into Lua, so the code this guards is gone. Closing as superseded.

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.

2 participants