fix: sanitize Org previews before trusting rendered HTML

This commit is contained in:
tdurieux
2026-09-06 10:46:44 +02:00
parent cf58aa330b
commit b2dfda1838
4 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"core.min.js": "core.6332b3c288.min.js",
"vendor.min.js": "vendor.a5d94d956f.min.js",
"vendor.min.js": "vendor.1020f4867e.min.js",
"mermaid.min.js": "mermaid.f848a72d16.min.js",
"all.min.css": "all.99ce8f3e14.min.css"
}
+1 -1
View File
@@ -2961,7 +2961,7 @@ angular
suppressSubScriptHandling: true,
suppressAutoLink: false,
});
$scope.content = $sce.trustAsHtml(orgHTMLDocument.toString());
$scope.content = $sce.trustAsHtml(DOMPurify.sanitize(orgHTMLDocument.toString()));
$scope.type = "html";
}
if (
+1 -1
View File
File diff suppressed because one or more lines are too long
+8
View File
@@ -66,4 +66,12 @@ describe("frontend production regressions", function () {
expect(template).to.include("treeNodes");
expect(h.scope.treeNodes[0].path).to.equal("/constructor/index.js");
});
it("sanitizes Org output before trusting it", async function () {
const h = explorer(); let untrusted;
h.context.Org = { Parser: function () { this.parse = () => ({ convert: () => ({ toString: () => '<img onerror="probe()">' }) }); }, ConverterHTML: {} };
h.context.contentAbs2Relative = x => x;
h.context.DOMPurify = { sanitize: html => { untrusted = html; return "sanitized"; } };
h.navigate("file.org"); h.requests.at(-1).resolve({ data: "org source", headers: () => "text/plain" }); await h.flush();
expect(untrusted).to.include("onerror"); expect(h.scope.content).to.equal("sanitized");
});
});