Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix(workers): sanitize reddits metascraper output

Mohamed Bassemba3db953c0d8
diff --git a/apps/workers/scripts/parseHtmlSubprocess.ts b/apps/workers/scripts/parseHtmlSubprocess.ts
index 9f32f3ce..62ac4dec 100644
--- a/apps/workers/scripts/parseHtmlSubprocess.ts
+++ b/apps/workers/scripts/parseHtmlSubprocess.ts
@@ -124,9 +124,19 @@ async function main() {
logger.info(`[Crawler][${jobId}] Done extracting metadata from the page.`);
// Conditionally run readability (skip if metascraper already provided readable content, e.g. Reddit plugin)
- let readableContent: { content: string } | null = meta.readableContentHtml
- ? { content: meta.readableContentHtml }
- : null;
+ let readableContent: { content: string } | null = null;
+ if (meta.readableContentHtml) {
+ // Sanitize plugin-provided HTML through DOMPurify (the extractReadableContent
+ // path already does this, but the direct-content path was missing it).
+ const purifyWindow = new JSDOM("").window;
+ try {
+ const purify = DOMPurify(purifyWindow);
+ const purifiedHTML = purify.sanitize(meta.readableContentHtml);
+ readableContent = { content: purifiedHTML };
+ } finally {
+ purifyWindow.close();
+ }
+ }
if (!readableContent) {
logger.info(