Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Disable eval in pdf.js #10450

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading