CVE-2024-45047: Svelte Cross-Site Scripting Vulnerability
MODERATECVE-2024-45047 is a MODERATE (CVSS 5.4) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Svelte libraries in the npm ecosystem. The issue involves svelte has a potential mxss vulnerability due to improper html escaping. Remediation is available by upgrading affected packages to version 4.2.19.
CVE-2024-45047 at a Glance
Security Impact
CVSS: 5.4
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:L/I:L/A:N).
How to Fix CVE-2024-45047
To remediate this vulnerability, upgrade all affected Svelte dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install svelte@4.2.19
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls svelte
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2024-45047, inspect your project dependencies using npm:
npm ls svelte
Analyze the terminal output to locate any version of Svelte in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.2.19), your application is affected.
Note: The npm ls svelte 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 Svelte, 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
CVE-2024-45047 Affected Svelte Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
svelte
|
npm |
< 4.2.19
|
4.2.19
|
References
Frequently Asked Questions
What is CVE-2024-45047?
Which Svelte versions are affected?
What version fixes CVE-2024-45047?
Is svelte affected?
What is the CVSS score of CVE-2024-45047?
What CWE is associated with CVE-2024-45047?
How can I check npm dependencies for CVE-2024-45047?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-8266-84wp-wv5c",
"modified" : "2024-08-30T20:01:23Z",
"published" : "2024-08-30T16:49:10Z",
"aliases" : [ "CVE-2024-45047" ],
"summary" : "Svelte has a potential mXSS vulnerability due to improper HTML escaping",
"details" : "### Summary\n\nA potential XSS vulnerability exists in Svelte for versions prior to 4.2.19.\n\n### Details\n\nSvelte improperly escapes HTML on server-side rendering. It converts strings according to the following rules:\n\n- If the string is an attribute value:\n - `\"` -> `"`\n - `&` -> `&`\n - Other characters -> No conversion\n- Otherwise:\n - `<` -> `<`\n - `&` -> `&`\n - Other characters -> No conversion\n\nThe assumption is that attributes will always stay as such, but in some situation the final DOM tree rendered on browsers is different from what Svelte expects on server-side rendering. This may be leveraged to perform XSS attacks. More specifically, this can occur when injecting malicious content into an attribute within a `<noscript>` tag.\n\n### PoC\n\nA vulnerable page (`+page.svelte`):\n```html\n<script>\nimport { page } from \"$app/stores\"\n\n// user input\nlet href = $page.url.searchParams.get(\"href\") ?? \"https://example.com\";\n</script>\n\n<noscript>\n <a href={href}>test</a>\n</noscript>\n```\n\nIf a user accesses the following URL,\n```\nhttp://localhost:4173/?href=</noscript><script>alert(123)</script>\n```\nthen, `alert(123)` will be executed.\n\n### Impact\n\nXSS, when using an attribute within a noscript tag",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N"
}, {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "svelte"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "4.2.19"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/sveltejs/svelte/security/advisories/GHSA-8266-84wp-wv5c"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-45047"
}, {
"type" : "WEB",
"url" : "https://github.com/sveltejs/svelte/commit/83e96e044deb5ecbae2af361ae9e31d3e1ac43a3"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/sveltejs/svelte"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-79" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2024-08-30T16:49:10Z",
"nvd_published_at" : "2024-08-30T17:15:15Z"
}
}