From 6cab4158946418ae1d77609754048305a9b60bec Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:44:32 -0500 Subject: [PATCH] fix(desktop): validate group padding before hidden ID masking (#12708) * fix(desktop): validate group padding before hidden ID masking * test(desktop): compact group padding overrides --- src/desktop/LinuxApplicationInventory.test.ts | 10 ++++++---- src/domain/desktop/desktopEntry.ts | 11 ++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/desktop/LinuxApplicationInventory.test.ts b/src/desktop/LinuxApplicationInventory.test.ts index 22c3e4046d..7e07779a41 100644 --- a/src/desktop/LinuxApplicationInventory.test.ts +++ b/src/desktop/LinuxApplicationInventory.test.ts @@ -253,6 +253,8 @@ describe.skipIf(process.platform === "win32")( it.each([ { before: "", extra: "this is not a key\n", invalidLine: 3 }, { before: "[Other]\nName=Other\n", extra: "", invalidLine: 1 }, + { header: "\u00a0[Desktop Entry]", invalidLine: 1 }, + { header: "[Desktop Entry]\u00a0", invalidLine: 1 }, { before: "", extra: "", @@ -267,8 +269,8 @@ describe.skipIf(process.platform === "win32")( }, ])( "refuses a hidden override with malformed structure at line $invalidLine", - async ({ before, extra, trailing = "", invalidLine }) => { - const entry = `${before}[Desktop Entry]\nType=Application\n${extra}Name=User notes\nExec=notes-app\n`; + async ({ before, extra, header, trailing = "", invalidLine }) => { + const entry = `${before ?? ""}${header ?? "[Desktop Entry]"}\nType=Application\n${extra ?? ""}Name=User notes\nExec=notes-app\n`; const { inspect, file } = await userOverride( `${entry}Hidden=true\n${trailing}`, ); @@ -294,10 +296,10 @@ describe.skipIf(process.platform === "win32")( }, ); - it("masks a minimal Application with a localized key and a valid action group", async () => { + it("masks a minimal Application with ASCII group padding and localized keys", async () => { const { inspect } = await userOverride( [ - "[Desktop Entry]", + "\t[Desktop Entry] \t", "Type=Application", 'Name=Notes "[Bad[Group]"', "Name[fr]=Notes locales", diff --git a/src/domain/desktop/desktopEntry.ts b/src/domain/desktop/desktopEntry.ts index 3e20d75926..0fb7e711ad 100644 --- a/src/domain/desktop/desktopEntry.ts +++ b/src/domain/desktop/desktopEntry.ts @@ -32,7 +32,10 @@ export interface DesktopEntry { readonly malformed_line?: number; } -const GROUP = new RegExp(`^${DESKTOP_GROUP}$`, "u"); +// Capture tolerant padding separately so it stays available for validation. +const GROUP = new RegExp(String.raw`^(\s*)${DESKTOP_GROUP}(\s*)$`, "u"); +const GLIB_GROUP_LEADING_SPACE = /^[ \t\f\r]*$/u; +const GLIB_GROUP_TRAILING_SPACE = /^[ \t]*$/u; const INVALID_GROUP_NAME_CHARACTER = /[[\]\u0000-\u001f\u007f]/u; const LINE_WITH_SEPARATOR = new RegExp(`(${DESKTOP_LINE_BREAK})`, "u"); // Only LF separates records; Unicode line/paragraph separators are value data. @@ -123,11 +126,13 @@ const readDesktopEntryFields = (text: string) => { const raw = parts[index]!; const line = raw.trim(); if (line.length === 0 || line.startsWith("#")) continue; - const header = GROUP.exec(line)?.[1]; + const [, leading = "", header, trailing = ""] = GROUP.exec(raw) ?? []; if (header !== undefined) { if ( (group === undefined && header !== DESKTOP_ENTRY_GROUP) || - INVALID_GROUP_NAME_CHARACTER.test(header) + INVALID_GROUP_NAME_CHARACTER.test(header) || + !GLIB_GROUP_LEADING_SPACE.test(leading) || + !GLIB_GROUP_TRAILING_SPACE.test(trailing) ) malformedLine ??= index / 2 + 1; // Preserve the group boundary for tolerant field and rewrite consumers.