CVE-2022-23647: Prismjs Cross-Site Scripting Vulnerability

HIGH
Advisory Identifier: GHSA-3949-f494-cm99
CVSS 7.5
CWE-79
Published
Advisory Summary

CVE-2022-23647 is a HIGH (CVSS 7.5) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Prismjs libraries in the npm ecosystem. The issue involves cross-site scripting in prism. Remediation is available by upgrading affected packages to version 1.27.0.

CVE-2022-23647 at a Glance

CVE Identifier CVE-2022-23647
GHSA Identifier GHSA-3949-f494-cm99
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Prismjs
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.5

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

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

How to Fix CVE-2022-23647

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

prismjs fixed: 1.27.0
npm install prismjs@1.27.0
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 prismjs

How to Check if You Are Affected

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

npm ls prismjs

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

Note: The npm ls prismjs 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 Prismjs, 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

### Impact Prism's [Command line plugin](https://prismjs.com/plugins/command-line/) can be used by attackers to achieve an XSS attack. The Command line plugin did not properly escape its output, leading to the input text being inserted into the DOM as HTML code. Server-side usage of Prism is not impacted. Websites that do not use the Command Line plugin are also not impacted. ### Patches This bug has been fixed in v1.27.0. ### Workarounds Do not use the Command line plugin on untrusted inputs, or sanitized all code blocks (remove all HTML code text) from all code blocks that use the Command line plugin. ### References - https://github.com/PrismJS/prism/pull/3341

CVE-2022-23647 Affected Prismjs Versions

1 component(s)
Fixed Versions:
1.27.0
Product / Package Ecosystem Affected Versions Fixed Version
prismjs
npm
≥ 1.14.0
< 1.27.0
1.27.0

References

Frequently Asked Questions

What is CVE-2022-23647?
CVE-2022-23647 is a security vulnerability in Prismjs involving Cross-site Scripting in Prism under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Prismjs versions are affected?
Affected versions include releases prior to 1.27.0 across affected packages: prismjs.
What version fixes CVE-2022-23647?
Upgrading to 1.27.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is prismjs affected?
Yes, prismjs is affected in releases prior to 1.27.0. Upgrade your dependency to 1.27.0 or later.
What is the CVSS score of CVE-2022-23647?
CVE-2022-23647 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:L/A:L.
What CWE is associated with CVE-2022-23647?
CVE-2022-23647 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-2022-23647?
Run the dependency tree command: 'npm ls prismjs'. 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-3949-f494-cm99",
  "modified" : "2022-02-22T19:32:18Z",
  "published" : "2022-02-22T19:32:18Z",
  "aliases" : [ "CVE-2022-23647" ],
  "summary" : "Cross-site Scripting in Prism",
  "details" : "### Impact\nPrism's [Command line plugin](https://prismjs.com/plugins/command-line/) can be used by attackers to achieve an XSS attack. The Command line plugin did not properly escape its output, leading to the input text being inserted into the DOM as HTML code.\n\nServer-side usage of Prism is not impacted. Websites that do not use the Command Line plugin are also not impacted.\n\n### Patches\nThis bug has been fixed in v1.27.0.\n\n### Workarounds\nDo not use the Command line plugin on untrusted inputs, or sanitized all code blocks (remove all HTML code text) from all code blocks that use the Command line plugin.\n\n### References\n- https://github.com/PrismJS/prism/pull/3341",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "prismjs"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.14.0"
      }, {
        "fixed" : "1.27.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/PrismJS/prism/security/advisories/GHSA-3949-f494-cm99"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-23647"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PrismJS/prism/pull/3341"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/PrismJS/prism/commit/e002e78c343154e1c0ddf9d6a0bb85689e1a5c7c"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/PrismJS/prism"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-02-22T19:32:18Z",
    "nvd_published_at" : "2022-02-18T15:15:00Z"
  }
}