Skip to content

Require a per-session token for notification click-exec - #13312

Closed
chessing234 wants to merge 2 commits into
omacom:quattrofrom
chessing234:fix/8433-notification-exec-token
Closed

chessing234 wants to merge 2 commits into
omacom:quattrofrom
chessing234:fix/8433-notification-exec-token

Conversation

@chessing234

Copy link
Copy Markdown
Contributor

Summary

  • Mint a per-session token under $XDG_RUNTIME_DIR/omarchy/notification-exec-token when the notifications service starts, and honor omarchy-exec-argv only when the matching omarchy-exec-token hint is present.
  • omarchy-notification-send --exec fails closed if the token file is unreadable; forged click-exec from sandboxed session-bus clients (Flatpak etc.) no longer works.
  • Token mint starts with the service (not after Component.onCompleted), restore waits for it, and restored popups clear execArgv so pre-token snapshots cannot keep click-to-exec.

Fixes #8433.

Test plan

  • bash test/shell.d/notification-send-test.sh
  • bash test/shell.d/notifications-test.sh

Made with Cursor

Sandboxed same-uid bus clients can forge omarchy-exec-argv; mint a token
under XDG_RUNTIME_DIR that only host helpers can read, and ignore click
commands whose omarchy-exec-token does not match.

Closes omacom#8433.
Start the token Process immediately so early --exec senders see the
file, restore only after mint completes, and drop execArgv from disk
snapshots so pre-token popups cannot keep click-to-exec.
@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: For newly received notifications, the token gate works as described. execArgvFromHints returns the argv only when the expected token is non-empty and the omarchy-exec-token hint matches it exactly. The check runs on receive, on in-place replacements and on do-not-disturb writes. Quickshell 0.3.1 replaces hints wholesale on update, so a replaces_id update cannot reuse an earlier valid token. omarchy-notification-send --exec attaches the token, and its callers are all host-side scripts. The new sender and JavaScript tests pass at the head and fail against the base code, as intended.

Two parts of the second commit do not fully do what the PR describes. Both respond to points raised on the earlier PR #12912.

Restored toasts lose their click action, but history replay still runs persisted argv

restorePopups clears execArgv only on the in-memory row (Service.qml:798). The popup file keeps it:

  • normal popups are re-persisted with execArgv just before the clear (lines 787-793);
  • critical popups (duration 0) are not rewritten at all.

When the toast leaves the screen, the file moves to history/. showHistory (Super + Shift + Alt + comma) replays it through historyEntry, which copies execArgv (NotificationLogic.js:256), and a click runs it through invokePopupDefault.

popup file on disk (execArgv kept) --restore--> on-screen row: execArgv = ""   (click only dismisses)
                                   \--dismiss--> history/ --showHistory--> execArgv restored  (click runs argv)

Impact:

  • Legitimate toasts lose their action on every shell restart. Every update run restarts the shell. On a fresh install, clicking "Update System" leaves the critical "Learn Keybindings" toast on screen, but its click then only dismisses it. Crash and pending-migration toasts behave the same way. Before this PR, the docs said a restored toast "clicks through exactly like a live one".
  • Pre-upgrade forged entries remain runnable through history replay (restore-then-dismiss, or entries already in history/). This needs an entry forged before the upgrade plus a later click from history.
  • The new docs reason ("the token is session-scoped") does not explain the clear. Argv persisted since this change was already validated on receipt and is never checked against the token again; only pre-token entries need clearing.

In an isolated Node run of the head NotificationLogic.js, a pre-upgrade forged record and a token-validated record both produced runnable argv through historyRows + parseExecArgv. The QML ordering above comes from source inspection; no live shell was run.

Suggested change (untested): Mark token-validated entries when persisting, for example execVerified: true beside a non-empty execArgv. Then blank execArgv in parsePopupFiles for any record without the mark (set the mark after popupEntry and check it before, since popupEntry and historyEntry rebuild entries with fixed fields). This strips pre-token entries on both the restore and the history paths, keeps validated actions across restarts (as step 4 of #8433 proposed) and makes the unconditional entry.execArgv = "" unnecessary. A smaller fix is to apply the same clear in the history path and persist the cleared value, at the cost of the legitimate actions.

The startup race between token minting and notification readiness remains

The PR says starting the mint with running: true makes the token exist "before early --exec senders race the bus claim" (Service.qml:424-428). In the Quickshell v0.3.1 source, Process only launches its child in the post-reload pass (process.cpp:41-48,180-183). The NotificationServer bus-name claim and the IpcHandler go live in that same pass. execToken is set only after the child exits. The ordering is therefore the same as starting the mint from Component.onCompleted, and the guard if (service.execToken) at line 893 cannot be true when it runs.

omarchy-notification-wait (IPC ping + GetServerInformation) and the NameHasOwner check in omarchy-restart-shell still do not wait for the token. The token is also re-minted on every shell start.

Runs of the head sender (busctl stub, synthetic runtime dir) plus the head receiver logic:

State at send time Result
Token file missing (first shell start of a login) --exec exits 1 and busctl is not called: no toast at all
Previous shell's token still on disk Toast sent; the receiver drops the click argv
Empty file (read between truncate and write) exits 1, no toast

Impact: Callers that send right after the readiness checks can lose the toast or its action. omarchy-migrate-notify falls back to journal text. A crash toast from omarchy-crash-watch is not re-sent. Post-update invitation hooks mark themselves done before sending, so a lost toast there is not retried. The window is probably short, but the PR presents the ordering as fixed and nothing orders it. Frequency on a live shell was not measured.

Suggested change (untested): Create the NotificationServer only after the mint has finished (for example behind a Loader gated on a mint-finished flag). Then, whenever the mint succeeds, the existing bus-name readiness checks also mean the token file and execToken are current. Minting once per login session (only when the file is missing or empty, written to a temp file and mv'd into place) would also remove the stale-token and empty-read cases across restarts.

Smaller notes

Optional test improvement: The new Service.qml assertions only check that strings are present. Two mutants pass the head suite:

  • The mint Process set to running: false. The regex /id: mintExecTokenProc[\s\S]*?running: true/ (test line 776) also matches the text "(running: true)" in the comment at Service.qml:890.
  • Restore no longer waiting for the token. The "restores popups only after the token" assertion only checks that the strings startRestoreAfterToken and entry.execArgv = "" exist, not where the restore is called.

Anchoring the regex to the Process block and asserting the call inside onStreamFinished would catch both.

Documentation:

  • The comment at NotificationLogic.js:144-146 still says the argv keeps restored toasts clickable.
  • docs/notifications.md:150-152 still presents omarchy-notification-wait as enough for senders near a shell restart, which does not hold for --exec.
  • Test description typo: "untoked".

Dependency: openssl is not listed in install/omarchy-base.packages. It is very likely present on Arch as a dependency of core packages; this was not verified. Without it, the mint fails closed and every --exec click is disabled.

Overlapping PR: Open PR #12111 still contains a separate exec-token writer for the same notification-exec-token file on the same files. Landing both as they stand would conflict or leave two token writers.


Review information

Test scope: Pinned head and base source, including the Quickshell v0.3.1 Process and notification server source. The PR's two test suites ran at head and base, plus mutants of the head. The head sender ran with a busctl stub and a synthetic runtime dir. The head and base NotificationLogic.js ran in Node, with synthetic records. The tests of the --exec callers ran at head and base; they stub the sender. There was no live Quickshell, D-Bus, click or Flatpak run, and the startup window was not measured on a live shell. The QML ordering claims rest on source inspection.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@chessing234

Copy link
Copy Markdown
Contributor Author

startup token race and restorePopups clearing execArgv are still real. bigger than a drive-by; leaving open.

@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 4bd222e on a worker built from the Omarchy ISO, running a live shell from this branch, with the base (7b336b1) for comparison. Codex Medium reviewed it as a second opinion.

The bug is real and the gate fixes the direct path. On base, a raw Notify carrying omarchy-exec-argv and no token gets its click executed, including from a bubblewrap sandbox that has the host bus socket but its own $XDG_RUNTIME_DIR, as Flatpak arranges it. On this head the same notifications are inert, and omarchy-notification-send --exec still runs its click. notification-send-test.sh (18) and notifications-test.sh (146) pass on the worker, and the new tests fail against the base code. ./test/cli has one failure (vscode generated theme references current theme file) that base has too.

The token can still reach a sandbox, through the image copy. Codex found this one and I reproduced it on the live shell. persistablePopup (NotificationLogic.js:340) copies any absolute app_icon or image-path byte for byte into ~/.local/state/omarchy/notifications/images/ (Service.qml:541), whether or not it is an image. A sandboxed sender that can read the home directory but not the runtime dir sends one notification with app_icon set to $XDG_RUNTIME_DIR/omarchy/notification-exec-token, reads the 64-character copy from images/<stamp>-appIcon, and attaches it to a forged omarchy-exec-argv. On the worker that click ran outside the sandbox. A Flatpak with filesystem=home is exactly that sandbox, so the gate does not hold while the copy path accepts any file. Refusing that one path by name would not be enough, since a symlink elsewhere would get around it. The source of a copy has to be resolved or allowlisted, which #12111 starts on.

The live shell also confirms the regressions raised earlier:

  • A critical --exec toast that survives omarchy-restart-shell loses its click on this head (Service.qml:798), and base runs it. Updates restart the shell, so this hits the first-run and crash toasts.
  • History replay can still run a persisted argv. The file keeps execArgv because it is re-persisted before the clear, or never rewritten for a critical toast, and historyEntry (NotificationLogic.js:256) carries it back. In two runs the restored-then-dismissed toast ran from Super + Shift + Alt + comma once. So pre-token entries are not reliably stripped, and the click lost on restore can come back.
  • An --exec sent as soon as org.freedesktop.Notifications has an owner again, which is all omarchy-restart-shell waits for, lost its click in 3 of 3 runs on this head, and base ran it 3 of 3. The sender reads the previous shell's token, or none, before the new mint lands. When the file is missing or caught mid-write, omarchy-notification-send exits before sending, so the whole toast is lost, not just its action.

Each of these needs a design decision (where the token lives and when it rotates, gating the NotificationServer on the mint, marking verified entries when they are persisted, which image sources may be copied), not a small patch. So nothing was pushed to this branch. The author has said they are leaving those for someone else, so this waits on the maintainer to decide how the gate should be finished, and whether that happens here or in #12111, which writes the same token file.

@ryanrhughes

Copy link
Copy Markdown
Collaborator

Thanks @chessing234! In the new notification engine (#15932) the exec hint stays structural: a JSON argv that's validated and run as positional args, never re-parsed as a shell string. A per-session token is something I've deliberately left out. A same-user process can already run whatever it wants without a notification, so the token doesn't buy much (that reasoning is in docs/notifications.md). Closing for that reason, but thanks for the careful threat model.

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.

Hardening: honor omarchy-exec-argv only from senders holding a per-session token (sandboxed bus clients can currently get click-to-exec)

4 participants