Просмотр исходного кода

refac/sec: sanitize note pdf download

Timothy Jaeryang Baek 3 месяцев назад
Родитель
Сommit
03cc6ce8eb
1 измененных файлов с 3 добавлено и 1 удалено
  1. 3 1
      src/lib/components/notes/utils.ts

+ 3 - 1
src/lib/components/notes/utils.ts

@@ -1,3 +1,5 @@
+import DOMPurify from 'dompurify';
+
 export const downloadPdf = async (note) => {
 	const [{ default: jsPDF }, { default: html2canvas }] = await Promise.all([
 		import('jspdf'),
@@ -9,7 +11,7 @@ export const downloadPdf = async (note) => {
 	const virtualHeight = 1400; // Fixed height (adjust as needed)
 
 	// STEP 1. Get a DOM node to render
-	const html = note.data?.content?.html ?? '';
+	const html = DOMPurify.sanitize(note.data?.content?.html ?? '');
 	const isDarkMode = document.documentElement.classList.contains('dark');
 
 	let node;