RubySec

Providing security resources for the Ruby community

GHSA-52c5-vh7f-26fx (prosemirror_to_html): Cross-Site Scripting (XSS) vulnerability through unescaped HTML attribute values

ADVISORIES

GEM

prosemirror_to_html

SEVERITY

CVSS v3.x: 7.6 (High)

PATCHED VERSIONS

  • >= 0.2.1

DESCRIPTION

Impact

The prosemirror_to_html gem is vulnerable to Cross-Site Scripting (XSS) attacks through malicious HTML attribute values. While tag content is properly escaped, attribute values are not, allowing attackers to inject arbitrary JavaScript code.

Who is impacted:

  • Any application using prosemirror_to_html to convert ProseMirror documents to HTML
  • Applications that process user-generated ProseMirror content are at highest risk
  • End users viewing the rendered HTML output could have malicious JavaScript executed in their browsers

Attack vectors include:

  • href attributes with javascript: protocol: <a href="javascript:alert(document.cookie)">
  • Event handlers: <div onclick="maliciousCode()">
  • onerror attributes on images: <img src=x onerror="alert('XSS')">
  • Other HTML attributes that can execute JavaScript

Patches

A fix is currently in development. Users should upgrade to version 0.2.1 or later once released.

The patch escapes all HTML attribute values using CGI.escapeHTML to prevent injection attacks.

Workarounds

Until a patched version is available, users can implement one or more of these mitigations:

  1. Sanitize output: Pass the HTML output through a sanitization library like Sanitize or Loofah:
   html = ProsemirrorToHtml.render(document)
   safe_html = Sanitize.fragment(html, Sanitize::Config::RELAXED)
  1. Implement Content Security Policy (CSP): Add strict CSP headers to prevent inline JavaScript execution:
    Content-Security-Policy: default-src 'self'; script-src 'self'
    
  2. Input validation: If possible, validate and sanitize ProseMirror documents before conversion to prevent malicious content from entering the system.

References

RELATED