From 2c305b35c9cdae62fa7f0b719085f7d835fefeb7 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 19 Oct 2026 10:08:07 +0200 Subject: fix(notify): harden sound hints from the final review A sound-file must be a regular file: a FIFO blocked the player on open and a device such as /dev/urandom played noise. A sound-name containing a path separator or .. is refused instead of being cleaned into a lookup outside the theme. The search roots are read once per lookup. Co-Authored-By: Claude Opus 5.5 --- internal/notify/sounds_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'internal/notify/sounds_test.go') diff --git a/internal/notify/sounds_test.go b/internal/notify/sounds_test.go index 060bbbe..060b927 100644 --- a/internal/notify/sounds_test.go +++ b/internal/notify/sounds_test.go @@ -14,6 +14,7 @@ package notify import ( "os" "path/filepath" + "syscall" "testing" "github.com/godbus/dbus/v5" @@ -88,6 +89,10 @@ func TestSoundFromHints(t *testing.T) { if err := os.WriteFile(file, []byte("x"), 0o644); err != nil { t.Fatal(err) } + fifo := filepath.Join(t.TempDir(), "pipe") + if err := syscall.Mkfifo(fifo, 0o600); err != nil { + t.Fatal(err) + } v := dbus.MakeVariant cases := []struct { name string @@ -102,6 +107,9 @@ func TestSoundFromHints(t *testing.T) { {"missing file rejected", map[string]dbus.Variant{"sound-file": v(file + ".gone")}, "", false}, {"bad file falls to name", map[string]dbus.Variant{"sound-file": v("x"), "sound-name": v("bell")}, root + "/freedesktop/stereo/bell.oga", false}, {"suppress", map[string]dbus.Variant{"suppress-sound": v(true), "sound-name": v("bell")}, root + "/freedesktop/stereo/bell.oga", true}, + {"fifo rejected", map[string]dbus.Variant{"sound-file": v(fifo)}, "", false}, + {"device rejected", map[string]dbus.Variant{"sound-file": v("/dev/null")}, "", false}, + {"name with a path rejected", map[string]dbus.Variant{"sound-name": v("../freedesktop/stereo/bell")}, "", false}, {"wrong types", map[string]dbus.Variant{"suppress-sound": v("yes"), "sound-name": v(3)}, "", false}, } for _, c := range cases { -- cgit v1.2.3