jsPDF is a library to generate PDFs in JavaScript. Prior to version 4.0.0, user control of the first argument of the loadFile method in the node.js build allows local file inclusion/path traversal. If given the possibility to pass unsanitized paths to the loadFile method, a user can retrieve file contents of arbitrary files in the local file system the node process is running in. The file contents are included verbatim in the generated PDFs. Other affected methods are `addImage`, `html`, and `addFont`. Only the node.js builds of the library are affected, namely the `dist/jspdf.node.js` and `dist/jspdf.node.min.js` files. The vulnerability has been fixed in jsPDF@4.0.0. This version restricts file system access per default. This semver-major update does not introduce other breaking changes. Some workarounds areavailable. With recent node versions, jsPDF recommends using the `--permission` flag in production. The feature was introduced experimentally in v20.0.0 and is stable since v22.13.0/v23.5.0/v24.0.0. For older node versions, sanitize user-provided paths before passing them to jsPDF.
jsPDF library versions prior to 4.0.0 in Node.js environments contain a path traversal vulnerability (CWE-35) allowing attackers to read arbitrary local files through unsanitized paths in loadFile, addImage, html, and addFont methods. Exploited files are embedded verbatim in generated PDFs, enabling unauthorized access to sensitive system files with CVSS score of 7.5.
تؤثر هذه الثغرة الأمنية على مكتبة jsPDF المستخدمة لإنشاء ملفات PDF في بيئة JavaScript، حيث يمكن للمهاجم استغلال عدم تعقيم المدخلات في المعامل الأول لدالة loadFile والدوال المرتبطة بها للوصول إلى ملفات النظام المحلية خارج نطاق التطبيق. تسمح الثغرة بقراءة محتويات الملفات الحساسة مثل ملفات الإعدادات وبيانات الاعتماد وتضمينها مباشرة في مستندات PDF المُنتجة. تقتصر الثغرة على إصدارات Node.js من المكتبة فقط (dist/jspdf.node.js و dist/jspdf.node.min.js) ولا تؤثر على إصدارات المتصفح. تم إصلاح الثغرة في الإصدار 4.0.0 من خلال تقييد الوصول إلى نظام الملفات افتراضياً.
تحتوي مكتبة jsPDF في الإصدارات السابقة للإصدار 4.0.0 في بيئات Node.js على ثغرة اجتياز المسارات (CWE-35) تسمح للمهاجمين بقراءة ملفات محلية عشوائية من خلال مسارات غير معقمة في دوال loadFile وaddImage وhtml وaddFont. يتم تضمين الملفات المستغلة حرفياً في ملفات PDF المُنشأة مما يتيح الوصول غير المصرح به للملفات الحساسة بدرجة خطورة 7.5.
1. Immediately upgrade jsPDF to version 4.0.0 or later in all Node.js applications, prioritizing production environments and systems processing sensitive data.
2. Conduct security audit of all code using loadFile, addImage, html, and addFont methods to identify and sanitize user-controlled input paths, implementing whitelist validation for allowed file paths.
3. Implement application-level access controls and file system sandboxing to restrict Node.js process permissions, and review generated PDFs for any inadvertently exposed sensitive information from past operations.
1. الترقية الفورية لمكتبة jsPDF إلى الإصدار 4.0.0 أو أحدث في جميع تطبيقات Node.js مع إعطاء الأولوية لبيئات الإنتاج والأنظمة التي تعالج البيانات الحساسة.
2. إجراء مراجعة أمنية شاملة لجميع الأكواد البرمجية التي تستخدم دوال loadFile وaddImage وhtml وaddFont لتحديد وتعقيم مسارات الملفات المتحكم بها من المستخدم، مع تطبيق التحقق من القائمة البيضاء للمسارات المسموح بها.
3. تطبيق ضوابط الوصول على مستوى التطبيق وعزل نظام الملفات لتقييد صلاحيات عمليات Node.js، ومراجعة ملفات PDF المُنشأة للكشف عن أي معلومات حساسة تم كشفها عن غير قصد من العمليات السابقة.