VYPR
Moderate severityNVD Advisory· Published Sep 5, 2021· Updated Sep 16, 2024

Cross-site Scripting (XSS)

CVE-2021-23439

Description

This affects the package file-upload-with-preview before 4.2.0. A file containing malicious JavaScript code in the name can be uploaded (a user needs to be tricked into uploading such a file).

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
file-upload-with-previewnpm
< 4.2.04.2.0

Affected products

1

Patches

Vulnerability mechanics

Root cause

"The library assigned the file name to `innerHTML` without sanitization, allowing HTML/JavaScript in the file name to be executed in the page context."

Attack vector

An attacker crafts a file whose name contains malicious JavaScript code (e.g. `<img src=x onerror=alert(1)>.jpg`). A user must be tricked into uploading such a file through the file-upload-with-preview component. When the library displays the file name in the input label, the unsanitized name is injected into the DOM via `innerHTML`, causing the attacker's script to execute in the context of the user's session [CWE-79]. The attack requires no special network position beyond serving the vulnerable page to the victim.

Affected code

The vulnerability resides in the `FileUploadWithPreview` class, specifically in the method that updates the input label after a file is selected. In the bundled output (`dist/file-upload-with-preview.umd.js` and `dist/file-upload-with-preview.esm.js`), the line `this.inputLabel.innerHTML = file.name;` was replaced with `this.inputLabel.textContent = file.name;` [patch_id=6635401]. This change prevents the file name from being interpreted as HTML, closing the cross-site scripting vector.

What the fix does

The patch changes `this.inputLabel.innerHTML = file.name;` to `this.inputLabel.textContent = file.name;` in both the UMD and ESM bundles [patch_id=6635401]. The `textContent` property automatically HTML-encodes the assigned string, so any HTML or JavaScript embedded in the file name is rendered as plain text rather than executed. This eliminates the stored cross-site scripting vector without altering the library's API or behavior.

Preconditions

  • configThe victim must be using a version of file-upload-with-preview before 4.2.0.
  • inputThe attacker must craft a file whose name contains malicious JavaScript code.
  • inputThe victim must be tricked into uploading the maliciously-named file via the file-upload component.

Generated on Jun 20, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

5

News mentions

0

No linked articles in our index yet.