Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): escape HTML around note icons

Elian Dorane2d5017dfda7
diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts
index eca313bca1..7bf3f5fa89 100644
--- a/apps/client/src/services/note_autocomplete.ts
+++ b/apps/client/src/services/note_autocomplete.ts
@@ -315,7 +315,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
suggestion: (suggestion) => {
if (suggestion.action === "command") {
let html = `<div class="command-suggestion">`;
- html += `<span class="command-icon ${suggestion.icon || "bx bx-terminal"}"></span>`;
+ html += `<span class="command-icon ${escapeHtml(suggestion.icon || "bx bx-terminal")}"></span>`;
html += `<div class="command-content">`;
html += `<div class="command-name">${suggestion.highlightedNotePathTitle}</div>`;
if (suggestion.commandDescription) {
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 4594d64564..170db6af73 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -13,7 +13,7 @@ import date_notes from "../../../services/date_notes";
import dialog from "../../../services/dialog";
import froca from "../../../services/froca";
import { t } from "../../../services/i18n";
-import { isMobile } from "../../../services/utils";
+import { escapeHtml, isMobile } from "../../../services/utils";
import CollectionProperties from "../../note_bars/CollectionProperties";
import ActionButton from "../../react/ActionButton";
import Button, { ButtonGroup } from "../../react/Button";
@@ -356,7 +356,7 @@ function useEventDisplayCustomization(parentNote: FNote, componentId: string | u
}
if (titleContainer) {
- const icon = /*html*/`<span class="${iconClass}"></span> `;
+ const icon = /*html*/`<span class="${escapeHtml(iconClass)}"></span> `;
titleContainer.insertAdjacentHTML("afterbegin", icon);
}
}
diff --git a/apps/client/src/widgets/type_widgets/text/snippets.ts b/apps/client/src/widgets/type_widgets/text/snippets.ts
index a791dd75b4..3a48192dee 100644
--- a/apps/client/src/widgets/type_widgets/text/snippets.ts
+++ b/apps/client/src/widgets/type_widgets/text/snippets.ts
@@ -4,6 +4,7 @@ import type LoadResults from "../../../services/load_results.js";
import search from "../../../services/search.js";
import type { TemplateDefinition } from "@triliumnext/ckeditor5";
import type FNote from "../../../entities/fnote.js";
+import { escapeHtml } from "../../../services/utils.js";
interface TemplateData {
title: string;
@@ -56,7 +57,7 @@ function buildIcon(snippet: FNote) {
return /*xml*/`\
<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<foreignObject x="0" y="0" width="20" height="20">
- <span class="note-icon ${snippet.getIcon()} ${snippet.getColorClass()}" xmlns="http://www.w3.org/1999/xhtml"></span>
+ <span class="note-icon ${escapeHtml(snippet.getIcon())} ${escapeHtml(snippet.getColorClass())}" xmlns="http://www.w3.org/1999/xhtml"></span>
</foreignObject>
</svg>`
}
diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.ts
index a1624acb0c..dba4b90a6f 100644
--- a/apps/server/src/share/content_renderer.ts
+++ b/apps/server/src/share/content_renderer.ts
@@ -498,7 +498,7 @@ function cleanUpReferenceLinks(linkEl: HTMLElement, getNote: GetNoteFunction) {
} else if (note.isProtected) {
linkEl.innerHTML = "[protected]";
} else {
- linkEl.innerHTML = `<span><span class="${note.getIcon()}"></span>${utils.escapeHtml(note.title)}</span>`;
+ linkEl.innerHTML = `<span><span class="${escapeHtml(note.getIcon())}"></span>${utils.escapeHtml(note.title)}</span>`;
}
}