Safeguard
Vulnerability Analysis•

CVE-2021-3838: Critical PHAR Deserialization in Dompdf

CVE-2021-3838 lets uploaded files trigger PHAR deserialization in Dompdf before 2.0.0, with possible code execution. Update to 2.0.0 and review uploads.

Safeguard Security Team
4 min read

CVE-2021-3838 is a critical (CVSS 9.8) PHAR deserialization flaw in Dompdf, the PHP HTML to PDF library, affecting versions before 2.0.0. An attacker who can place a file on the server may reach arbitrary object instantiation and possibly code execution. Upgrade to Dompdf 2.0.0 or later.

What's affected

  • Dompdf (dompdf/dompdf) before version 2.0.0, per the NVD record and its description.
  • Fixed in 2.0.0. The referenced upstream commit changes how Dompdf handles URI schemes, and the PHAR scheme is not enabled by default after the change.
  • Highest risk where an application also lets users upload files of any type, and where a framework such as Laravel is present, because the record notes documented POP chains in such frameworks.
  • No KEV listing: the record shows kev as false, and neither source we read reports exploitation in the wild.

How to check if you're exposed

Dompdf is usually pulled in through Composer, often as a transitive dependency of a reporting or invoicing package. These commands show the version and who requires it.

composer show dompdf/dompdf
composer why dompdf/dompdf

Any version below 2.0.0 is affected. Also look for code that passes user-controlled paths or URLs into Dompdf, and for upload features that accept arbitrary file types.

What to do now

  1. Run composer update dompdf/dompdf after raising the constraint in composer.json to ^2.0, then test your PDF templates, because 2.0.0 changed option handling.
  2. Review how the new Options class is configured in your code. The commit moves protocol rules into that class, so any custom configuration needs a second look.
  3. Restrict uploads to the file types you actually need and store them outside paths that PHP functions can be pointed at by user input.
  4. Search your code for places where a user supplied value reaches a file or URL argument, and validate the scheme before use.
  5. Re-scan your lockfile to confirm that no other package still bundles an older Dompdf.

Why it matters

The weakness is CWE-502, deserialization of untrusted data. PHP can read metadata from a PHAR archive when a path starts with the phar scheme, and that metadata is turned back into live objects. If the application has classes that do something dangerous when created or destroyed, an attacker who controls the archive can steer those side effects. The record says Dompdf did not check the protocol before handing a path to file_get_contents, so the dangerous scheme could get through.

What makes this worse than a typical library bug is the dependence on the surrounding application. Dompdf itself does not need to contain the dangerous classes. A framework or plugin on the same server can supply them. That is why dependency inventories matter here: a PDF library you forgot you had can be the entry point.

Try it yourself

Click through it at your own pace, or open it full screen.

Quick check

Do I need file upload ability for this to be exploitable?

The record says the attacker needs to be able to upload files of any type to the server. If your application has no such feature and no other way to place files, the practical risk is lower, but upgrading is still the right call.

Is the fix just a version bump?

The fix is in 2.0.0, but the release changed how protocol rules and options are handled. Test your PDF output after upgrading.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

We email you a link to confirm, and only then add you to the list. Unsubscribe in one click. Privacy

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.