Skip to content

Commit

Permalink
🔐 security: Disable user-input eval in pdfjs-dist usage.
Browse files Browse the repository at this point in the history
By default, pdfjs-dist optimizes some path resolution logic by compiling
a JavaScript function on the fly. The function is built using string
concatenation and no effort is made at sanitizing the parts it is
built from. These parts could contain user-input which leads to a code
injection vulnerability. This commit disables this default behavior.
An alternative is to upgrade pdfjs-dist to v4.2.67 or later.

For reference, see:
  - https://bugzilla.mozilla.org/show_bug.cgi?id=1893645
  - https://www.cve.org/CVERecord?id=CVE-2024-4367
  - https://security.snyk.io/vuln/SNYK-JS-PDFJSDIST-6810403
  - GHSA-wgrm-67xf-hhpq
  - mozilla/pdf.js#18015
  - wojtekmaj/react-pdf#1786
  - https://security.stackexchange.com/questions/248462/\
    is-firefoxs-new-javascript-support-within-pdf-files-a-security-concern/\
    248985
  - https://stackoverflow.com/questions/49299000/\
    what-are-the-security-implications-of-the-isevalsupported-option-in-pdf-js
  - mozilla/pdf.js#10818

Not sure if this will break anything and/or will make certain things
slower.
  • Loading branch information
make-github-pseudonymous-again committed May 11, 2024
1 parent 499fcb7 commit dd6ca32
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions imports/lib/pdf/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function fetchPDF({
cMapUrl = CMAP_URL,
cMapPacked = CMAP_PACKED,
standardFontDataUrl = STANDARD_FONT_DATA_URL,
isEvalSupported = false,
...rest
}: DocumentInitParameters) {
const pdfjs = Meteor.isClient
Expand All @@ -27,8 +28,13 @@ export async function fetchPDF({
// pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
}

return pdfjs.getDocument({cMapUrl, cMapPacked, standardFontDataUrl, ...rest})
.promise;
return pdfjs.getDocument({
cMapUrl,
cMapPacked,
standardFontDataUrl,
isEvalSupported,
...rest,
}).promise;
}

export async function saveHTMLElementAsPDF(
Expand Down

0 comments on commit dd6ca32

Please sign in to comment.