Skip to content

Build your personal knowledge base with Trilium Notes

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.ts
index 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>&lt;img src=x onerror=&quot;alert(1)&quot;&gt; 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.ts
index 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>`;
}