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
fix(import): escape the Anytype callout icon to prevent HTML injection
Elian Doran6a1de184369e
diff --git a/packages/trilium-core/src/services/import/anytype/content.spec.ts b/packages/trilium-core/src/services/import/anytype/content.spec.tsindex 8e35f5ad53..59348b8946 100644--- a/packages/trilium-core/src/services/import/anytype/content.spec.ts+++ b/packages/trilium-core/src/services/import/anytype/content.spec.ts@@ -105,6 +105,11 @@ describe("callouts", () => {expect(parseObject(doc).content).toBe('<aside class="admonition note"><p>😶🌫️ Foggy</p></aside>');});+ it("escapes the callout icon so a crafted iconEmoji can't inject markup", () => {+ const doc = listDoc(["c1"], [{ id: "c1", text: { text: "Hi", style: "Callout", marks: { marks: [] }, iconEmoji: '<img src=x onerror="alert(1)">' } }]);+ expect(parseObject(doc).content).toBe('<aside class="admonition note"><p><img src=x onerror="alert(1)"> Hi</p></aside>');+ });+it("applies inline marks in the callout body and renders child blocks inside the aside", () => {const doc = listDoc(["c1"],diff --git a/packages/trilium-core/src/services/import/anytype/content.ts b/packages/trilium-core/src/services/import/anytype/content.tsindex de3aa83a5f..f04be7c11a 100644--- a/packages/trilium-core/src/services/import/anytype/content.ts+++ b/packages/trilium-core/src/services/import/anytype/content.ts@@ -144,7 +144,9 @@ export function extractContent(blocks: AnytypeBlock[], rootId: string, resolveLi// the emoji kept at the start of the body (admonitions have no per-block icon).const emoji = block.text?.iconEmoji ?? "";const type = emoji ? "note" : "tip";- const lead = [emoji, renderInlineText(rawText, marks)].filter(Boolean).join(" ");+ // Escape the emoji like every other piece of user text here — it's interpolated raw into the+ // markup, so an export carrying markup in this field would otherwise inject it.+ const lead = [escapeHtml(emoji), renderInlineText(rawText, marks)].filter(Boolean).join(" ");const firstPara = lead ? `<p>${lead}</p>` : "";return `<aside class="admonition ${type}">${firstPara}${renderSequence(block.childrenIds ?? [])}</aside>`;}