From 1ccf994112f3b7aff0dc5dde3d9b305dffae9a59 Mon Sep 17 00:00:00 2001 From: dmitriylaukhin Date: Mon, 6 Jul 2026 13:44:41 +0500 Subject: [PATCH] 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. --- src/lib/clean-pdf/__tests__/template.test.ts | 8 ++++++++ src/lib/clean-pdf/template.ts | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/lib/clean-pdf/__tests__/template.test.ts b/src/lib/clean-pdf/__tests__/template.test.ts index 2a74221..d97829c 100644 --- a/src/lib/clean-pdf/__tests__/template.test.ts +++ b/src/lib/clean-pdf/__tests__/template.test.ts @@ -42,6 +42,14 @@ describe("buildCleanHtml", () => { expect(new Set(ids).size).toBe(3); }); + it("вырезает script и inline-обработчики из контента", () => { + const html = buildCleanHtml({ ...base, contentHtml: `

t

x` }); + expect(html).not.toContain("