Strip active content from extracted HTML before PDF print
Defuddle-extracted article content is injected raw into the PDF HTML and rendered by a real browser (browserless). As defense-in-depth against a compromised or malicious source page, remove script/style/ iframe/object/embed elements and on* event-handler / javascript: href attributes from the parsed DOM before serializing it into the template.
This commit is contained in:
@@ -42,6 +42,14 @@ describe("buildCleanHtml", () => {
|
||||
expect(new Set(ids).size).toBe(3);
|
||||
});
|
||||
|
||||
it("вырезает script и inline-обработчики из контента", () => {
|
||||
const html = buildCleanHtml({ ...base, contentHtml: `<p onclick="alert(1)">t</p><script>alert(2)</script><a href="javascript:alert(3)">x</a>` });
|
||||
expect(html).not.toContain("<script>alert(2)");
|
||||
expect(html).not.toContain("onclick");
|
||||
expect(html).not.toContain("javascript:alert(3)");
|
||||
expect(html).toContain(">t<");
|
||||
});
|
||||
|
||||
it("переключает тёмную тему", () => {
|
||||
const light = buildCleanHtml({ ...base, contentHtml: "<p>x</p>" });
|
||||
const dark = buildCleanHtml({ ...base, theme: "dark", contentHtml: "<p>x</p>" });
|
||||
|
||||
Reference in New Issue
Block a user