Cross-site Scripting (XSS)
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.
| Package | Affected versions | Patched versions |
|---|---|---|
file-upload-with-previewnpm | < 4.2.0 | 4.2.0 |
Affected products
1Patches
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- github.com/advisories/GHSA-97pv-4338-r5vpghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-23439ghsaADVISORY
- github.com/johndatserakis/file-upload-with-preview/blob/develop/src/file-upload-with-preview.js%23L168ghsax_refsource_MISCWEB
- github.com/johndatserakis/file-upload-with-preview/pull/40/filesghsax_refsource_MISCWEB
- snyk.io/vuln/SNYK-JS-FILEUPLOADWITHPREVIEW-1579492ghsax_refsource_MISCWEB
News mentions
0No linked articles in our index yet.