The vulnerability is a DOM-based Cross-Site Scripting (XSS) issue within the SCEditor library, identified as GHSA-25fq-6qgg-qpj8. The root cause is the lack of input sanitization for configuration options passed to the editor's constructor (sceditor.create()). An attacker with control over these options could inject malicious code.
The analysis of the patch commit 5733aed4f0e257cb78e1ba191715fc458cbd473d reveals several key points of failure:
-
Unsanitized Emoticon URLs: The proof of concept demonstrates that the emoticons configuration option can be exploited. The code in src/lib/SCEditor.js (the SCEditor constructor) and src/lib/defaultCommands.js (the defaultCmds.emoticon._dropDown function) directly used URLs from this configuration to construct <img> tags' src attributes. The patch applies escape.uriScheme to these URLs to prevent malicious schemes like javascript:, or embedded HTML through quote escaping.
-
Insecure Template Rendering: The core template function in src/lib/templates.js performed simple string replacement without escaping or sanitizing the values. This meant any configuration option rendered via this template function was a potential XSS vector. The patch rectifies this by integrating DOMPurify for robust HTML sanitization and adding entity escaping for template parameters by default.
-
Other Unsanitized Options: The patch also adds sanitization for other options like style and charset in the main SCEditor constructor, indicating a broader pattern of insufficient input validation for configuration settings.
In summary, the vulnerability was triggered during the editor's initialization and UI component rendering (like the emoticon dropdown), where configuration options were insecurely embedded into the DOM. The identified vulnerable functions are the primary locations where this insecure handling occurred.