Skip to content

Commit

Permalink
Desktop: Disable eval in pdf.js (#10450)
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed May 21, 2024
1 parent 3312bd2 commit 9fcaf5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/lib/shim-init-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> => {
const loadingTask = pdfJs.getDocument(pdfPath);
const loadingTask = getPdfJsDocument(pdfPath);
const doc = await loadingTask.promise;
const textByPage = [];

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/pdf-viewer/PdfDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9fcaf5b

Please sign in to comment.