Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/collections/board: sanitize column names in the item context menu
Adorian Doran39208c59c3d3
diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.tsindex fa58a21e97..4055be0e32 100644--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts@@ -397,6 +397,24 @@ describe("Board item context menu", () => {expect(focusCard).toHaveBeenCalledWith(expect.any(String));});+ /**+ * A column is named by the reader, and the menu reads a title as markup, so a crafted name+ * would otherwise plant whatever it liked in the menu.+ */+ it("escapes a column name rather than letting it stand as markup", () => {+ const api = {+ columns: [ "Done <button id=\"planted\">press</button>" ],+ isColumnArchived: () => false,+ getColumnIcon: () => DEFAULT_COLUMN_ICON,+ getColumnColorClass: () => ""+ } as unknown as BoardApi;++ const [ column ] = statusItems(api);++ expect(column && "title" in column ? column.title : undefined)+ .toBe("Done <button id="planted">press</button>");+ });+it("shows each column with the icon and colour it carries", () => {const api = {columns: [ "To Do", "Done" ],diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.tsindex b4d86eca62..346ca371a8 100644--- a/apps/client/src/widgets/collections/board/context_menu.ts+++ b/apps/client/src/widgets/collections/board/context_menu.ts@@ -9,6 +9,7 @@ import branches from "../../../services/branches";import dialog from "../../../services/dialog";import { getArchiveMenuItem } from "../../../menus/context_menu_utils";import { t } from "../../../services/i18n";+import { escapeHtml } from "../../../services/utils";import ColorPicker from "../../react/ColorPicker";import Api from "./api";@@ -181,7 +182,10 @@ function buildColumnItems(api: Api, note: FNote, column: string, onFocusCard: (noteId: string) => void): MenuItem<CommandNames>[] {return api.columns.map((name) => ({- title: name,+ // The menu reads a title as markup, and a column is named by the reader, so what a crafted+ // name would plant there is escaped into the text it is meant to be. Every other title the+ // board builds from a name goes through `t()`, which escapes what it interpolates.+ title: escapeHtml(name),uiIcon: api.getColumnIcon(name),iconColorClass: api.getColumnColorClass(name),// The one it is already under is shown rather than hidden, so the list reads as the whole