diff --git a/cmd/gui/renderer/app.js b/cmd/gui/renderer/app.js index c211670..df7f9ef 100644 --- a/cmd/gui/renderer/app.js +++ b/cmd/gui/renderer/app.js @@ -43,6 +43,7 @@ const state = { pendingTools: [], eventSource: null, chatFinalIdx: -1, + sseLastEventID: "", // 最近一次 SSE 事件 id,断线重连时随 Last-Event-ID 头回传 lang: localStorage.getItem("ha-lang") || "zh", connections: [], currentConn: null, @@ -325,6 +326,29 @@ function toggleAppearance() { })(); // ===== Utility ===== +// 安全渲染 markdown:marked 转 HTML 后由 DOMPurify 剥离脚本/事件/危险标签。 +// CDN 加载失败时降级为纯转义文本,绝不把未消毒 HTML 直接写入 innerHTML。 +function renderMd(text) { + if (typeof text !== "string") text = String(text || ""); + var html; + if (typeof marked !== "undefined") { + try { html = marked.parse(text); } + catch (e) { html = escHtml(text); } + } else { + html = "
" + escHtml(text) + ""; + } + if (typeof DOMPurify !== "undefined" && typeof DOMPurify.sanitize === "function") { + try { return DOMPurify.sanitize(html, { USE_PROFILES: { html: true } }); } + catch (e) {} + } + // 兜底:手动删除 + +