Skip to content

Critical XSS vulnerabilities in image alt, srcset, and sizes attributes #1742

@laurentgoudet

Description

@laurentgoudet

Description

A critical Cross-Site Scripting (XSS) vulnerability was discovered in lightgallery where HTML attribute values were not properly escaped before being inserted into the DOM.

This allows attackers to inject malicious HTML and JavaScript through user-controlled attributes like alt, srcset, sizes, and iframe title.

This is especially dangerous as, while modern Javascript frameworks (React, Vue, Angular) perform automatic encoding and escaping, using lightgallery in a React/Vue/Angular application bypasses these safety nets, as the values are passed directly to this library, outside of the framework's control.

Severity

Critical - Allows arbitrary JavaScript execution in the context of the application

Affected Versions

All versions prior to the fix

Steps to reproduce

  1. Create a gallery with an image that has a malicious alt attribute
  2. Open the gallery
  3. Malicious code executes

Fix is in #1741. The included tests are initially failing.

JS code that you use to initialize lightGallery.

lightGallery(document.getElementById('lightgallery'));

Sample HTML markup

<div id="lightgallery">
    <a href="img/img1.jpg">
        <img alt='"><img src=x onerror=alert(1)>' src="img/thumb1.jpg" />
    </a>
</div>

Environment

  • Browser and version - All browsers
  • OS - All operating systems
  • lightGallery version - All versions prior to fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions