Skip to content

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

Closed
chessing234 wants to merge 1 commit into
omacom:quattrofrom
chessing234:fix/notification-exec-token
Closed

chessing234 wants to merge 1 commit into
omacom:quattrofrom
chessing234:fix/notification-exec-token

Conversation

@chessing234

@chessing234 chessing234 commented Sep 22, 2026 •

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.
  • Validated execArgv still persists across restarts; the token is never written to popup/history snapshots.

Closes #8433

Test plan

  • bash test/shell.d/notifications-test.sh (token match/mismatch, no token in persistence, service mint path)
  • bash test/shell.d/notification-send-test.sh (token attached with --exec, fail closed without token file)
  • Click an Omarchy toast sent with --exec still runs the command when the shell is up
  • A Notify call with only a forged omarchy-exec-argv hint shows a toast but has no click command

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.
@llstrk

llstrk commented Sep 23, 2026

Copy link
Copy Markdown

Two edge cases remain: notification readiness can precede token readiness, and pre-upgrade click commands remain trusted after restoration.

Verified: At d3391515, the sender attaches the token for --exec, and the receive/replacement logic drops argv with a missing, wrong or not-yet-minted token. Matching-token argv survives persistence without storing the token itself.

Include token minting in notification readiness

Service.qml starts minting asynchronously, but omarchy-notification-wait checks only IPC ping and GetServerInformation. Neither waits for service.execToken to be populated.

The real sender and notification logic produced these results with synthetic runtime state and a stubbed notification transport:

State at send time Result
Token file absent --exec fails without sending a toast
Previous token still on disk; receiver expects a different token Send succeeds, but the receiver drops the click command
File and receiver token match Click argv is retained

Impact: Startup/restart callers can lose a notification or receive a toast without its advertised action despite passing the existing readiness check. The pending-migrations caller falls back to terminal/journal text when sending fails. These tests model the ordering; live scheduling and its frequency were not measured.

Suggested change: Make the readiness contract used by --exec callers wait until minting has completed and the service has loaded the same token exposed to senders. File readability alone does not exclude the stale-token window.

Pre-upgrade persisted click commands remain trusted

The old service accepted unauthenticated argv hints and saved them as execArgv. The new restore path carries that field forward without distinguishing old snapshots from token-validated ones:

Before upgrade: forged Notify -> old service persists execArgv
After upgrade:  saved critical popup -> restored argv -> runnable on click

A synthetic old critical-popup record retained a runnable argv through the current parsePopupFiles and parseExecArgv functions. Source inspection connects that result to the restore and click paths; no live upgrade attack was executed.

Impact: A forged toast planted while the old shell was running can remain actionable after the hardening update. This requires a pre-existing unvalidated entry and a later click, not a fresh-notification bypass of the new token check. It does not require the confined sender to write the state directory directly.

Suggested change: Strip click argv from pre-token popup/history records, or mark newly token-validated records and accept restored actions only from those. This deliberately sacrifices click actions on legitimate old entries once, while preserving their text and subsequent validated actions across restarts.


Review information

Test scope: Pinned sender and JavaScript logic, synthetic runtime/token and legacy-popup data, stubbed notification transport, and source-path inspection. No live Quickshell click, Flatpak confinement test or measured startup race. The token boundary assumes the sender cannot obtain the token or modify trusted persisted state.

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

Automated AI review: Astra Medium performed initial inspection and synthesis, with independent Opus 5.5 High and GPT 6 Sol Xhigh technical reviews. Claims were checked against targeted evidence and source paths.

@jandrusk

Copy link
Copy Markdown

Thanks for tightening up --exec. I think there's a startup race that breaks the two callers that actually use it, though.

mintExecTokenProc runs asynchronously from Component.onCompleted, but NotificationServer claims the bus name as soon as the component loads. omarchy-notification-wait can therefore return before the token file has been written. Both omarchy-migrate-notify and omarchy-crash-watch wait and then send right away:

  • On login, the token file doesn't exist yet, so omarchy-notification-send --exec exits 1 and the "Pending Omarchy Migrations" notification is never shown. The failure only shows up in the journal.
  • After a shell crash or restart, the old token file is still there, so the sender attaches a stale token. The new shell minted a different one, so the crash notification appears but clicking it silently does nothing.

Suggested fix: keep one token for the whole login session, and have the sender wait briefly for it.

(a) Only mint the token when the file is missing or empty (in Service.qml):

set -euo pipefail
runtime="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
dir="$runtime/omarchy"; f="$dir/notification-exec-token"
mkdir -p -m 700 -- "$dir"
umask 077
if [[ ! -s $f ]]; then
  openssl rand -hex 32 >"$f.$$" && mv -f -- "$f.$$" "$f"
fi
cat -- "$f"

(b) In omarchy-notification-send, wait up to about 3 seconds for the first write:

for _ in {1..30}; do [[ -s $exec_token_file ]] && break; sleep 0.1; done

(c) A test where the token file is missing when the server comes up and appears shortly after would guard this.

Because $XDG_RUNTIME_DIR is cleared at logout, a per-session token keeps the same security property while surviving shell restarts.

@chessing234

Copy link
Copy Markdown
Contributor Author

folding into #12111 — session exec-token gate is already on the notification fold.

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.

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

3 participants