Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Escape configuration textarea values https://github.com/siyuan-note/siyuan/issues/19454

Daniel5bb1687db215
diff --git a/app/src/config/render/render.test.ts b/app/src/config/render/render.test.ts
index 24d2777236..b41ae22f61 100644
--- a/app/src/config/render/render.test.ts
+++ b/app/src/config/render/render.test.ts
@@ -19,6 +19,36 @@ describe("genNumberInputHtml", () => {
});
describe("genStackHtml", () => {
+ it("escapes textarea closing tags and literal character references", () => {
+ if (typeof Lute === "undefined") {
+ require("../../../stage/protyle/js/lute/lute.min.js");
+ }
+ const originalWindow = Object.getOwnPropertyDescriptor(globalThis, "window");
+ Object.defineProperty(globalThis, "window", {
+ configurable: true,
+ value: {siyuan: {config: {editor: {spellcheck: false}}}},
+ });
+ try {
+ const html = genStackHtml([{
+ left: {
+ kind: "textBlock", id: "macros", mode: "textarea",
+ readConfig: () => "</textarea><img src=x>\n&amp; &#60; &lt;",
+ readValue: (el) => (el as HTMLTextAreaElement).value,
+ },
+ }]);
+
+ assert.match(html, />&lt;\/textarea&gt;&lt;img src=x&gt;\n&amp;amp; &amp;#60; &amp;lt;<\/textarea>/);
+ assert.equal((html.match(/<\/textarea>/g) || []).length, 1);
+ assert.doesNotMatch(html, /<img/);
+ } finally {
+ if (originalWindow) {
+ Object.defineProperty(globalThis, "window", originalWindow);
+ } else {
+ Reflect.deleteProperty(globalThis, "window");
+ }
+ }
+ });
+
it("renders descriptions with controls using the primary text color", () => {
const html = genStackHtml([{
left: {kind: "desc", text: "Setting name"},
diff --git a/app/src/config/render/render.ts b/app/src/config/render/render.ts
index 89c94a4e8b..2d1958e4a6 100644
--- a/app/src/config/render/render.ts
+++ b/app/src/config/render/render.ts
@@ -69,7 +69,7 @@ const genTextBlockFieldHtml = (
): string => {
const spellcheck = window.siyuan.config.editor.spellcheck ? "true" : "false";
if (mode === "textarea") {
- return `<textarea class="b3-text-field fn__block" id="${id}" spellcheck="${spellcheck}">${value}</textarea>`;
+ return `<textarea class="b3-text-field fn__block" id="${id}" spellcheck="${spellcheck}">${Lute.EscapeHTMLStr(value)}</textarea>`;
}
if (mode === "input-password") {
return `<div class="b3-form__icona fn__block">