|
| 1 | +--- |
| 2 | +gem: prosemirror_to_html |
| 3 | +ghsa: 52c5-vh7f-26fx |
| 4 | +url: https://github.com/etaminstudio/prosemirror_to_html/security/advisories/GHSA-52c5-vh7f-26fx |
| 5 | +title: Cross-Site Scripting (XSS) vulnerability through unescaped |
| 6 | + HTML attribute values |
| 7 | +date: 2025-11-06 |
| 8 | +description: | |
| 9 | + ### Impact |
| 10 | +
|
| 11 | + The prosemirror_to_html gem is vulnerable to Cross-Site Scripting |
| 12 | + (XSS) attacks through malicious HTML attribute values. While tag |
| 13 | + content is properly escaped, attribute values are not, allowing |
| 14 | + attackers to inject arbitrary JavaScript code. |
| 15 | +
|
| 16 | + **Who is impacted:** |
| 17 | +
|
| 18 | + - Any application using prosemirror_to_html to convert ProseMirror |
| 19 | + documents to HTML |
| 20 | + - Applications that process user-generated ProseMirror content are |
| 21 | + at highest risk |
| 22 | + - End users viewing the rendered HTML output could have malicious |
| 23 | + JavaScript executed in their browsers |
| 24 | +
|
| 25 | + **Attack vectors include:** |
| 26 | +
|
| 27 | + - `href` attributes with `javascript:` protocol: |
| 28 | + `<a href="javascript:alert(document.cookie)">` |
| 29 | + - Event handlers: `<div onclick="maliciousCode()">` |
| 30 | + - `onerror` attributes on images: `<img src=x onerror="alert('XSS')">` |
| 31 | + - Other HTML attributes that can execute JavaScript |
| 32 | +
|
| 33 | + ### Patches |
| 34 | +
|
| 35 | + A fix is currently in development. Users should upgrade to version |
| 36 | + **0.2.1** or later once released. |
| 37 | +
|
| 38 | + The patch escapes all HTML attribute values using `CGI.escapeHTML` |
| 39 | + to prevent injection attacks. |
| 40 | +
|
| 41 | + ### Workarounds |
| 42 | +
|
| 43 | + Until a patched version is available, users can implement one or |
| 44 | + more of these mitigations: |
| 45 | +
|
| 46 | + 1. **Sanitize output**: Pass the HTML output through a sanitization |
| 47 | + library like [Sanitize](https://github.com/rgrove/sanitize) or |
| 48 | + [Loofah](https://github.com/flavorjones/loofah): |
| 49 | +
|
| 50 | + ```ruby |
| 51 | + html = ProsemirrorToHtml.render(document) |
| 52 | + safe_html = Sanitize.fragment(html, Sanitize::Config::RELAXED) |
| 53 | + ``` |
| 54 | +
|
| 55 | + 2. **Implement Content Security Policy (CSP)**: Add strict CSP |
| 56 | + headers to prevent inline JavaScript execution: |
| 57 | + ``` |
| 58 | + Content-Security-Policy: default-src 'self'; script-src 'self' |
| 59 | + ``` |
| 60 | +
|
| 61 | + 3. **Input validation**: If possible, validate and sanitize |
| 62 | + ProseMirror documents before conversion to prevent malicious |
| 63 | + content from entering the system. |
| 64 | +
|
| 65 | + ### References |
| 66 | +
|
| 67 | + - Vulnerable code: https://github.com/etaminstudio/prosemirror_to_html/blob/ea8beb32f6c37f29f042ba4155ccf18504da716e/lib/prosemirror_to_html.rb#L249 |
| 68 | + - [OWASP XSS Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html) |
| 69 | + - [CWE-79: Improper Neutralization of Input During Web Page Generation](https://cwe.mitre.org/data/definitions/79.html) |
| 70 | +cvss_v3: 7.6 |
| 71 | +patched_versions: |
| 72 | + - ">= 0.2.1" |
| 73 | +related: |
| 74 | + url: |
| 75 | + - https://github.com/etaminstudio/prosemirror_to_html/security/advisories/GHSA-52c5-vh7f-26fx |
| 76 | + - https://github.com/etaminstudio/prosemirror_to_html/releases/tag/v0.2.1 |
| 77 | + - https://github.com/etaminstudio/prosemirror_to_html/commit/4d59f94f550bcabeec30d298791bbdd883298ad8 |
| 78 | + - https://github.com/advisories/GHSA-52c5-vh7f-26fx |
0 commit comments