Background
Jodit is an open-source rich-text (WYSIWYG) editor written in TypeScript and distributed on npm. Web applications embed it wherever users write formatted text, such as content management systems and comment forms. The editing area is a normal piece of the host page, so anything running inside it runs with the page’s full privileges.
Because editors load HTML that came from somewhere else (a database, an import, another user), Jodit ships a clean-html plugin. Its job is to sanitize that HTML by removing scripts, event handler attributes such as onerror, and dangerous links before the content is displayed.
Terms used below:
- XSS (cross-site scripting) is the injection of attacker-controlled JavaScript into a page that other people view. The script runs as if the site itself had written it.
- Sanitizer is code that parses untrusted HTML, deletes the dangerous parts and passes along the rest.
- Mutation XSS (mXSS) is a sanitizer bypass where the HTML looks safe when checked, but changes meaning when it is parsed a second time.
- Carrier is the harmless-looking markup that wraps and hides the dangerous part during sanitization.
Summary
Attacker-controlled HTML can pass sanitization and execute JavaScript when assigned to the live editing area. A carrier combining noscript and style markup is interpreted differently during sanitization and insertion. It hides an event handler in text during the first parse and produces an active element during the second.
The proof of concept used normal value assignment. The application loaded a stored document into the editor, and the handler ran in the embedding page. Asynchronous cleanup later removed the handler, but could not undo execution. Checking only the final editor value would miss the failure.
How the Vulnerability Works
Browsers do not simply read HTML text. They parse it into a tree of elements (the DOM), and the parser’s rules depend on its settings. One setting is whether scripting is enabled. Jodit’s sanitizer parses content in a throwaway inert document where scripting is off. It cleans that tree and writes it back out as a string. The string is then assigned to the live editor, where scripting is on and the browser parses it all over again.
The two parses are supposed to agree. They do not when the content contains a <noscript> element. With scripting off, the contents of noscript are parsed as ordinary markup. With scripting on, they are treated as plain text that ends at the first </noscript>. The same characters therefore produce different trees.
A simplified version of the carrier looks like this (the handler is a placeholder):
<noscript><style></noscript><img src=1 onerror=...></style></noscript>| Parse | What the browser builds | What the sanitizer sees |
|---|---|---|
| 1. Sanitizer (scripting off) | A noscript holding a style element. Everything inside style is raw text, including the <img ...>. | No img, so nothing to remove |
| 2. Live editor (scripting on) | The noscript ends at the first </noscript>. The <img src=1 onerror=...> that follows is now a real element outside of it. | Never checked |
The image fails to load (src=1 does not point to a real image), the onerror handler fires, and the attacker’s JavaScript runs. A direct <img onerror=...> is removed correctly, which shows that only the parse differential is at fault. This class of bug is common in HTML sanitizers and has a history in Jodit itself, which is why the fix is to sanitize the tree that the live parser actually produced.
Prerequisites
The attacker must influence HTML that an application later assigns to editor.value. Stored comments, imported documents and collaborative content are possible sources. The victim must open that content through the affected value-set path.
The proof of concept used Chromium and the default configuration, in which the cleanHTML.useIframeSandbox option is off. The advisory confirms that Chromium-based browsers are affected. It does not establish identical behavior across all browsers or insertion APIs. Paste and node-insertion flows use a different sanitization sequence.
Attack Path
- STARTAttacker controls document HTML
- STEP 01Application assigns the document to editor.value
- STEP 02Inert-document sanitizer misses the hidden handler
The first parse sees text where the live parser later creates an element.
MITIGATION Remove noscript carriers before serialization
- STEP 03Live editor reparses the sanitized string
MITIGATION Sanitize the live tree synchronously after assignment
- STEP 04Event handler runs in the embedding page
Root Cause
The value-set sanitizer parses content in a document created with document.implementation.createHTMLDocument, where scripting is disabled. It walks that tree, then serializes it. setNativeEditorValue assigns the string to the live editor with scripting enabled.
HTML treats noscript differently under those two modes. In the crafted carrier, the first tree contains style text instead of an image with an event attribute. The sanitizer has no visible handler to remove. Serialization preserves the text, and the live parser turns the remaining bytes into an image with an active onerror handler.
A background pass removes the attribute later. Its timing is insufficient because the image error event can run first. Removing the handler from the final DOM does not prevent execution during assignment.
Validation
The proof of concept used the official Jodit 4.17.1 build and three stored documents. It recorded execution through a dedicated page variable and read a synthetic same-origin value. Merely finding payload text in the editor was not treated as proof.
| Document | Expected boundary | Recorded result |
|---|---|---|
| Benign paragraphs | Render without executing code | No execution |
| Direct image event handler | Strip the handler | No execution |
| Same handler inside the carrier | Preserve the sanitizer’s execution boundary | Handler ran and read synthetic page data |
The direct-handler control confirmed that ordinary event attributes were removed. The carrier ran again in a fresh browser context. The original research observed the same markup mutation in Firefox, but did not observe execution there because cleanup ran before the error event.
Impact
Injected JavaScript runs with the authority of the embedding page. It can read page data and make requests in the victim’s application context, subject to browser protections and the victim’s permissions.
The test read synthetic data to demonstrate the origin boundary. It did not use a real session secret or establish a separate server-side compromise. Overview uses the critical rating of 9.3 under CVSS v3.1 from the published GitHub advisory.
Remediation
Upgrade to 4.17.3 or later. The fix removes noscript elements and adds synchronous sanitization immediately after assigning the value to the live editor. That second pass examines the tree in the same parsing context that will execute events.
The published workaround is to strip noscript content before assignment or sanitize the live tree synchronously after assignment. Delayed cleanup is insufficient. Tests should observe execution while content loads, not only inspect the final HTML after background cleaning has finished.