CVE-2020-7642: Cross-site scripting in lazysizes

lazysizes Updated 02 Oct 2025

Summary

10/12/2021
Yes i
Moderate
5.4

CVE-2020-7642: Cross-site scripting in lazysizes. Affects lazysizes versions < 5.2.1. Fixed in 5.2.1. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

lazysizes is an npm package that provides lazy loading functionality for images and videos on websites. It allows developers to delay the loading of media content until it is needed, improving page load times and overall performance. However, lazysizes versions up to 5.2.0 are vulnerable to a cross-site scripting (XSS) attack. This vulnerability arises from the video-embed plugin's failure to sanitize certain attributes, including data-vimeo, data-vimeoparams, data-youtube, and data-ytparams. An attacker can exploit this vulnerability to inject and execute malicious JavaScript code.

Vulnerability Detail

The vulnerability in lazysizes versions up to 5.2.0 allows an attacker to execute arbitrary JavaScript code on a victim's browser. By injecting malicious code through the unsanitized attributes mentioned above, an attacker can potentially steal sensitive information, perform unauthorized actions on behalf of the victim, or manipulate the website's content. This vulnerability has a CVSS score of 5.4, indicating a moderate severity level.

How To Fix

Minimum fixed version

5.2.1

This is the first release that contains the fix.

npm install lazysizes@5.2.1

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If upgrading to the latest version is not immediately feasible, a temporary workaround is to manually sanitize the vulnerable attributes before using them. This can be done by implementing input validation and escaping techniques to prevent the execution of malicious JavaScript code. Here is an example of how to sanitize the 'data-vimeo' attribute:

const sanitizeAttribute = (attribute) => {
  return attribute.replace(/[<>&]/g, (c) => {
    switch (c) {
      case '<':
        return '&lt;';
      case '>':
        return '&gt;';
      case '&':
        return '&amp;';
    }
  });
};

const vimeoAttribute = sanitizeAttribute(videoElement.dataset.vimeo);

Conclusion

In conclusion, lazysizes versions up to 5.2.0 are vulnerable to a cross-site scripting (XSS) attack due to unsanitized attributes. This can allow an attacker to execute malicious JavaScript code on a victim's browser, potentially leading to various security risks. To mitigate this vulnerability, it is crucial to upgrade to lazysizes version 5.2.1 or later. Additionally, implementing input validation and escaping techniques can serve as a temporary workaround. For further assistance on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for lazysizes →

Share this vulnerability

FAQ

lazysizes is an npm package that provides lazy loading functionality for images and videos on websites. It helps improve page load times by delaying the loading of media content until it is needed.

lazysizes versions up to 5.2.0 are affected by this vulnerability. It is recommended to upgrade to version 5.2.1 or later to fix the issue.

An attacker can exploit this vulnerability by injecting malicious JavaScript code through the unsanitized attributes, such as data-vimeo, data-vimeoparams, data-youtube, and data-ytparams. This can lead to the execution of arbitrary code on a victim's browser.

The potential consequences of this vulnerability include the theft of sensitive information, unauthorized actions performed on behalf of the victim, and manipulation of the website's content.

Yes, the developers have released lazysizes version 5.2.1, which addresses this vulnerability. It is recommended to upgrade to the latest version to ensure the application is secure.

Related vulnerabilities

Recent vulnerabilities recorded for lazysizes.

How To Fix

Minimum fixed version

5.2.1

This is the first release that contains the fix.

npm install lazysizes@5.2.1

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback