diff --git a/packages/lib/shim-init-node.ts b/packages/lib/shim-init-node.ts index fea43da4f..b60409d62 100644 --- a/packages/lib/shim-init-node.ts +++ b/packages/lib/shim-init-node.ts @@ -736,8 +736,16 @@ function shimInit(options: ShimInitOptions = null) { } }; + const getPdfJsDocument = (path: string) => { + return pdfJs.getDocument({ + url: path, + // IMPORTANT: Set to false to mitigate CVE-2024-4367. + isEvalSupported: false, + }); + }; + shim.pdfExtractEmbeddedText = async (pdfPath: string): Promise => { - const loadingTask = pdfJs.getDocument(pdfPath); + const loadingTask = getPdfJsDocument(pdfPath); const doc = await loadingTask.promise; const textByPage = []; @@ -791,7 +799,7 @@ function shimInit(options: ShimInitOptions = null) { const filePrefix = `page_${Date.now()}`; const output: string[] = []; - const loadingTask = pdfJs.getDocument(pdfPath); + const loadingTask = getPdfJsDocument(pdfPath); const doc = await loadingTask.promise; try { diff --git a/packages/pdf-viewer/PdfDocument.ts b/packages/pdf-viewer/PdfDocument.ts index d592ba2d7..8e2b56317 100644 --- a/packages/pdf-viewer/PdfDocument.ts +++ b/packages/pdf-viewer/PdfDocument.ts @@ -20,9 +20,9 @@ export default class PdfDocument { this.rendererMutex = withTimeout(new Mutex(), 40 * 1000); } - public loadDoc = async (url: string | Uint8Array) => { + public loadDoc = async (url: string) => { this.url = url; - const loadingTask = pdfjsLib.getDocument(url); + const loadingTask = pdfjsLib.getDocument({ url, isEvalSupported: false }); try { const pdfDocument: any = await loadingTask.promise; this.doc = pdfDocument;