Vulnerabilities in pkg:npm/external-svg-loader

PACKAGE
Advisory Identifier: GHSA-xc2r-jf2x-gjr8
Advisory Summary

CVE-2023-40013 is a CRITICAL (CVSS 9.8) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting External svg loader libraries in the npm ecosystem. The issue involves external-svg-loader cross-site scripting vulnerability. Remediation is available by upgrading affected packages to version 1.6.9.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/external-svg-loader

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/external-svg-loader. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-xc2r-jf2x-gjr8 CVE-2023-40013 CRITICAL external-svg-loader Cross-site Scripting vulnerability

CVE-2023-40013 at a Glance

CVE Identifier CVE-2023-40013
GHSA Identifier GHSA-xc2r-jf2x-gjr8
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product External svg loader
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 9.8

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:N/S:U/C:H/I:H/A:H).

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

How to Fix CVE-2023-40013

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

external-svg-loader fixed: 1.6.9
npm install external-svg-loader@1.6.9
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 external-svg-loader

How to Check if You Are Affected

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

npm ls external-svg-loader

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

Note: The npm ls external-svg-loader 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 External svg loader, 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

### Summary According to the [docs](https://github.com/shubhamjain/svg-loader/tree/main#2-enable-javascript), svg-loader will strip all JS code before injecting the SVG file for security reasons but the input sanitization logic is not sufficient and can be trivially bypassed. This allows an attacker to craft a malicious SVG which can result in XSS. ### Details When trying to sanitize the svg the lib [removes event attributes](https://github.com/shubhamjain/svg-loader/blob/main/svg-loader.js#L125-L128) such as `onmouseover`, `onclick` but the list of events is not exhaustive. Here's a list of events not removed by svg-loader. `onafterscriptexecute, onbeforecopy, onbeforecut, onbeforescriptexecute, onbeforetoggle, onbegin, onbounce, onend, onfinish, onfocusin, onfocusout, onmousewheel, onpointerrawupdate, onrepeat, onsearch, onshow, onstart, ontoggle(popover), ontouchend, ontouchmove, ontouchstart` As you can see in the POC we can use `onbegin` in `animate` tag to execute JS code without needing to add `data-js="enabled"`. ### PoC ```html <svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg"> <animate onbegin=alert(1) attributeName=x dur=1s> </svg> ``` ```html <html> <head> <script src="./dist/svg-loader.js" type="text/javascript"></script> </head> <body> <svg data-src="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGJhc2VQcm9maWxlPSJmdWxsIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwb2x5Z29uIGlkPSJ0cmlhbmdsZSIgcG9pbnRzPSIwLDAgMCw1MCA1MCwwIiBmaWxsPSIjMDA5OTAwIiBzdHJva2U9IiMwMDQ0MDAiLz4KICA8YW5pbWF0ZSBvbmJlZ2luPWFsZXJ0KDEpIGF0dHJpYnV0ZU5hbWU9eCBkdXI9MXM+Cjwvc3ZnPgo="></svg> </body> </html> ``` ### Impact Any website which uses external-svg-loader and allows its users to provide svg src, upload svg files would be susceptible to stored XSS attack.

CVE-2023-40013 Affected External svg loader Versions

1 component(s)
Fixed Versions:
1.6.9
Product / Package Ecosystem Affected Versions Fixed Version
external-svg-loader
npm
< 1.6.9
1.6.9

References

Frequently Asked Questions

What is CVE-2023-40013?
CVE-2023-40013 is a security vulnerability in External svg loader involving external-svg-loader Cross-site Scripting vulnerability under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which External svg loader versions are affected?
Affected versions include releases prior to 1.6.9 across affected packages: external-svg-loader.
What version fixes CVE-2023-40013?
Upgrading to 1.6.9 (or the latest patched release for your respective branch) resolves the vulnerability.
Is external-svg-loader affected?
Yes, external-svg-loader is affected in releases prior to 1.6.9. Upgrade your dependency to 1.6.9 or later.
What is the CVSS score of CVE-2023-40013?
CVE-2023-40013 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2023-40013?
CVE-2023-40013 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-2023-40013?
Run the dependency tree command: 'npm ls external-svg-loader'. 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-xc2r-jf2x-gjr8",
  "modified" : "2023-08-14T21:32:27Z",
  "published" : "2023-08-14T21:32:27Z",
  "aliases" : [ "CVE-2023-40013" ],
  "summary" : "external-svg-loader Cross-site Scripting vulnerability",
  "details" : "### Summary\nAccording to the [docs](https://github.com/shubhamjain/svg-loader/tree/main#2-enable-javascript), svg-loader will strip all JS code before injecting the SVG file for security reasons but the input sanitization logic is not sufficient and can be trivially bypassed. This allows an attacker to craft a malicious SVG which can result in XSS. \n\n### Details\nWhen trying to sanitize the svg the lib [removes event attributes](https://github.com/shubhamjain/svg-loader/blob/main/svg-loader.js#L125-L128) such as `onmouseover`, `onclick` but the list of events is not exhaustive. Here's a list of events not removed by svg-loader. \n`onafterscriptexecute, onbeforecopy, onbeforecut, onbeforescriptexecute, onbeforetoggle, onbegin, onbounce, onend, onfinish, onfocusin, onfocusout, onmousewheel, onpointerrawupdate, onrepeat, onsearch, onshow, onstart, ontoggle(popover), ontouchend, ontouchmove, ontouchstart`\nAs you can see in the POC we can use `onbegin` in `animate` tag to execute JS code without needing to add `data-js=\"enabled\"`.\n\n### PoC\n\n```html\n<svg version=\"1.1\" baseProfile=\"full\" xmlns=\"http://www.w3.org/2000/svg\">\n  <animate onbegin=alert(1) attributeName=x dur=1s>\n</svg>\n\n```\n\n```html\n<html>\n    <head>\n        <script src=\"./dist/svg-loader.js\" type=\"text/javascript\"></script>\n    </head>\n    <body>\n        <svg data-src=\"data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGJhc2VQcm9maWxlPSJmdWxsIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwb2x5Z29uIGlkPSJ0cmlhbmdsZSIgcG9pbnRzPSIwLDAgMCw1MCA1MCwwIiBmaWxsPSIjMDA5OTAwIiBzdHJva2U9IiMwMDQ0MDAiLz4KICA8YW5pbWF0ZSBvbmJlZ2luPWFsZXJ0KDEpIGF0dHJpYnV0ZU5hbWU9eCBkdXI9MXM+Cjwvc3ZnPgo=\"></svg>\n    </body>\n</html>\n\n```\n\n### Impact\nAny website which uses external-svg-loader and allows its users to provide svg src, upload svg files would be susceptible to stored XSS attack.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "external-svg-loader"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.6.9"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/shubhamjain/svg-loader/security/advisories/GHSA-xc2r-jf2x-gjr8"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-40013"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/shubhamjain/svg-loader/commit/d3562fc08497aec5f33eb82017fa1417b3319e2c"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/shubhamjain/svg-loader"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/shubhamjain/svg-loader/blob/main/svg-loader.js#L125-L128"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/shubhamjain/svg-loader/tree/main#2-enable-javascript"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-08-14T21:32:27Z",
    "nvd_published_at" : "2023-08-14T21:15:13Z"
  }
}