CVE-2021-3838:PHAR Deserialization Vulnerability in DomPDF before version 2.0.0

splash
Back

Description Preview

DomPDF before version 2.0.0 contains a PHAR deserialization vulnerability due to insufficient validation of protocols when using file_get_contents(). Attackers who can upload files to the server can exploit this by using the phar:// protocol to trigger PHP object deserialization, potentially leading to remote code execution, especially when used with frameworks like Laravel that have known POP (Property Oriented Programming) chains.

Overview

This vulnerability (CVE-2021-3838) affects DomPDF library versions prior to 2.0.0. The issue stems from a lack of protocol validation before passing user-controlled input to PHP's file_get_contents() function. When an attacker can upload files to the server (of any type), they can leverage the phar:// protocol wrapper to trigger PHP object deserialization. This is particularly dangerous because when the deserialization occurs, PHP will instantiate objects defined in the PHAR file, potentially executing malicious code through magic methods like __destruct(), __wakeup(), etc. The vulnerability is especially critical when DomPDF is used alongside frameworks like Laravel that have documented PHP Object Injection chains, or when used in custom code with vulnerable class structures.

Remediation

  1. Update DomPDF to version 2.0.0 or later, which includes the security patch for this vulnerability.
  2. If immediate updating is not possible, implement additional validation for any file paths or URLs passed to DomPDF:
    • Explicitly whitelist allowed protocols (e.g., http://, https://, file://)
    • Block dangerous protocols like phar://, php://, zip://, data://
  3. Implement proper file upload validation to restrict file types and content
  4. Consider implementing a wrapper function around file_get_contents() that validates the protocol
  5. Apply the principle of least privilege to file system permissions for uploaded files
  6. Review your codebase for other instances where user input might influence file paths

References

  1. Patch: https://github.com/dompdf/dompdf/commit/99aeec1efec9213e87098d42eb09439e7ee0bb6a
  2. Vulnerability Report and Exploit: https://huntr.com/bounties/0bdddc12-ff67-4815-ab9f-6011a974f48e
  3. PHAR Deserialization Documentation: https://blog.secarma.co.uk/labs/near-phar-dangerous-unserialization-wherever-you-are
  4. PHP Object Injection: https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection
  5. CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes

Industry ExposureMost to least
This section illustrates the prevalence of a specific Common Vulnerabilities and Exposures (CVE) across various industries based on customer reports. The ranking displays industries from the most to least affected by this particular vulnerability, offering valuable insight into where this CVE has been most frequently observed. This information can help organizations within these sectors prioritize their security efforts, understand their relative risk exposure compared to their peers, and focus remediation strategies where they are most needed. By understanding the industry-specific impact, organizations can make more informed decisions regarding patching, resource allocation, and overall risk management related to this CVE.

  1. Finance and Insurance
    Finance and Insurance
  2. Manufacturing
    Manufacturing
  3. Public Administration
    Public Administration
  4. Accommodation & Food Services
    Accommodation & Food Services
  5. Administrative, Support, Waste Management & Remediation Services
    Administrative, Support, Waste Management & Remediation Services
  6. Agriculture, Forestry Fishing & Hunting
    Agriculture, Forestry Fishing & Hunting
  7. Arts, Entertainment & Recreation
    Arts, Entertainment & Recreation
  8. Construction
    Construction
  9. Educational Services
    Educational Services
  10. Health Care & Social Assistance
    Health Care & Social Assistance
  11. Information
    Information
  12. Management of Companies & Enterprises
    Management of Companies & Enterprises
  13. Mining
    Mining
  14. Other Services (except Public Administration)
    Other Services (except Public Administration)
  15. Professional, Scientific, & Technical Services
    Professional, Scientific, & Technical Services
  16. Real Estate Rental & Leasing
    Real Estate Rental & Leasing
  17. Retail Trade
    Retail Trade
  18. Transportation & Warehousing
    Transportation & Warehousing
  19. Utilities
    Utilities
  20. Wholesale Trade
    Wholesale Trade

Focus on What Matters

  1. See Everything.
  2. Identify True Risk.
  3. Proactively Mitigate Threats.

Let's talk!

background
Armis Vulnerability Intelligence Database