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