ghsa-m85w-3h95-hcf9
Vulnerability from github
Summary
A DOM Clobbering gadget has been discoverd in Astro's client-side router. It can lead to cross-site scripting (XSS) in websites enables Astro's client-side routing and has stored attacker-controlled scriptless HTML elements (i.e., iframe
tags with unsanitized name
attributes) on the destination pages.
Details
Backgrounds
DOM Clobbering is a type of code-reuse attack where the attacker first embeds a piece of non-script, seemingly benign HTML markups in the webpage (e.g. through a post or comment) and leverages the gadgets (pieces of js code) living in the existing javascript code to transform it into executable code. More for information about DOM Clobbering, here are some references:
[1] https://scnps.co/papers/sp23_domclob.pdf [2] https://research.securitum.com/xss-in-amp4email-dom-clobbering/
Gadgets found in Astro
We identified a DOM Clobbering gadget in Astro's client-side routing module, specifically in the <ViewTransitions />
component. When integrated, this component introduces the following vulnerable code, which is executed during page transitions (e.g., clicking an <a>
link):
https://github.com/withastro/astro/blob/7814a6cad15f06931f963580176d9b38aa7819f2/packages/astro/src/transitions/router.ts#L135-L156
However, this implementation is vulnerable to a DOM Clobbering attack. The document.scripts
lookup can be shadowed by an attacker injected non-script HTML elements (e.g., <img name="scripts"><img name="scripts">
) via the browser's named DOM access mechanism. This manipulation allows an attacker to replace the intended script elements with an array of attacker-controlled scriptless HTML elements.
The condition script.dataset.astroExec === ''
on line 138 can be bypassed because the attacker-controlled element does not have a data-astroExec attribute. Similarly, the check on line 134 can be bypassed as the element does not require a type
attribute.
Finally, the innerHTML
of an attacker-injected non-script HTML elements, which is plain text content before, will be set to the .innerHTML
of an script element that leads to XSS.
PoC
Consider a web application using Astro as the framework with client-side routing enabled and allowing users to embed certain scriptless HTML elements (e.g., form
or iframe
). This can be done through a bunch of website's feature that allows users to embed certain script-less HTML (e.g., markdown renderers, web email clients, forums) or via an HTML injection vulnerability in third-party JavaScript loaded on the page.
For PoC website, please refer to: https://stackblitz.com/edit/github-4xgj2d
. Clicking the "about" button in the menu will trigger an alert(1)
from an attacker-injected form
element.
```
import Header from "../components/Header.astro"; import Footer from "../components/Footer.astro"; import { ViewTransitions } from "astro:transitions"; import "../styles/global.css"; const { pageTitle } = Astro.props;
{pageTitle}
```
Impact
This vulnerability can result in cross-site scripting (XSS) attacks on websites that built with Astro that enable the client-side routing with ViewTransitions
and store the user-inserted scriptless HTML tags without properly sanitizing the name
attributes on the page.
Patch
We recommend replacing document.scripts
with document.getElementsByTagName('script')
for referring to script elements. This will mitigate the possibility of DOM Clobbering attacks leveraging the name
attribute.
Reference
Similar issues for reference: + Webpack (CVE-2024-43788) + Vite (CVE-2024-45812) + layui (CVE-2024-47075)
{ "affected": [ { "database_specific": { "last_known_affected_version_range": "\u003c= 4.16.0" }, "package": { "ecosystem": "npm", "name": "astro" }, "ranges": [ { "events": [ { "introduced": "3.0.0" }, { "fixed": "4.16.1" } ], "type": "ECOSYSTEM" } ] } ], "aliases": [ "CVE-2024-47885" ], "database_specific": { "cwe_ids": [ "CWE-79" ], "github_reviewed": true, "github_reviewed_at": "2024-10-14T20:02:21Z", "nvd_published_at": "2024-10-14T19:15:10Z", "severity": "MODERATE" }, "details": "### Summary\n\nA DOM Clobbering gadget has been discoverd in Astro\u0027s client-side router. It can lead to cross-site scripting (XSS) in websites enables Astro\u0027s client-side routing and has *stored* attacker-controlled scriptless HTML elements (i.e., `iframe` tags with unsanitized `name` attributes) on the destination pages.\n\n### Details\n\n#### Backgrounds\n\nDOM Clobbering is a type of code-reuse attack where the attacker first embeds a piece of non-script, seemingly benign HTML markups in the webpage (e.g. through a post or comment) and leverages the gadgets (pieces of js code) living in the existing javascript code to transform it into executable code. More for information about DOM Clobbering, here are some references:\n\n[1] https://scnps.co/papers/sp23_domclob.pdf\n[2] https://research.securitum.com/xss-in-amp4email-dom-clobbering/\n\n\n#### Gadgets found in Astro\n\nWe identified a DOM Clobbering gadget in Astro\u0027s client-side routing module, specifically in the `\u003cViewTransitions /\u003e` component. When integrated, this component introduces the following vulnerable code, which is executed during page transitions (e.g., clicking an `\u003ca\u003e` link):\n\nhttps://github.com/withastro/astro/blob/7814a6cad15f06931f963580176d9b38aa7819f2/packages/astro/src/transitions/router.ts#L135-L156\n\nHowever, this implementation is vulnerable to a DOM Clobbering attack. The `document.scripts` lookup can be shadowed by an attacker injected non-script HTML elements (e.g., `\u003cimg name=\"scripts\"\u003e\u003cimg name=\"scripts\"\u003e`) via the browser\u0027s named DOM access mechanism. This manipulation allows an attacker to replace the intended script elements with an array of attacker-controlled scriptless HTML elements. \n\nThe condition `script.dataset.astroExec === \u0027\u0027` on line 138 can be bypassed because the attacker-controlled element does not have a data-astroExec attribute. Similarly, the check on line 134 can be bypassed as the element does not require a `type` attribute.\n\nFinally, the `innerHTML` of an attacker-injected non-script HTML elements, which is plain text content before, will be set to the `.innerHTML` of an script element that leads to XSS.\n\n\n### PoC\n\nConsider a web application using Astro as the framework with client-side routing enabled and allowing users to embed certain scriptless HTML elements (e.g., `form` or `iframe`). This can be done through a bunch of website\u0027s feature that allows users to embed certain script-less HTML (e.g., markdown renderers, web email clients, forums) or via an HTML injection vulnerability in third-party JavaScript loaded on the page.\n\nFor PoC website, please refer to: `https://stackblitz.com/edit/github-4xgj2d`. Clicking the \"about\" button in the menu will trigger an `alert(1)` from an attacker-injected `form` element.\n\n```\n---\nimport Header from \"../components/Header.astro\";\nimport Footer from \"../components/Footer.astro\";\nimport { ViewTransitions } from \"astro:transitions\";\nimport \"../styles/global.css\";\nconst { pageTitle } = Astro.props;\n---\n\u003chtml lang=\"en\"\u003e\n \u003chead\u003e\n \u003cmeta charset=\"utf-8\" /\u003e\n \u003clink rel=\"icon\" type=\"image/svg+xml\" href=\"/favicon.svg\" /\u003e\n \u003cmeta name=\"viewport\" content=\"width=device-width\" /\u003e\n \u003cmeta name=\"generator\" content={Astro.generator} /\u003e\n \u003ctitle\u003e{pageTitle}\u003c/title\u003e\n \u003cViewTransitions /\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003c!--USER INPUT--\u003e\n \u003ciframe name=\"scripts\"\u003ealert(1)\u003c/iframe\u003e\n \u003ciframe name=\"scripts\"\u003ealert(1)\u003c/iframe\u003e\n \u003c!--USER INPUT--\u003e\n \n \u003cHeader /\u003e\n \u003ch1\u003e{pageTitle}\u003c/h1\u003e\n \u003cslot /\u003e\n \u003cFooter /\u003e\n \u003cscript\u003e\n import \"../scripts/menu.js\";\n \u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Impact\n\nThis vulnerability can result in cross-site scripting (XSS) attacks on websites that built with Astro that enable the client-side routing with `ViewTransitions` and store the user-inserted scriptless HTML tags without properly sanitizing the `name` attributes on the page.\n\n### Patch\n\nWe recommend replacing `document.scripts` with `document.getElementsByTagName(\u0027script\u0027)` for referring to script elements. This will mitigate the possibility of DOM Clobbering attacks leveraging the `name` attribute.\n\n### Reference\n\nSimilar issues for reference:\n+ Webpack ([CVE-2024-43788](https://github.com/webpack/webpack/security/advisories/GHSA-4vvj-4cpr-p986))\n+ Vite ([CVE-2024-45812](https://github.com/vitejs/vite/security/advisories/GHSA-64vr-g452-qvp3))\n+ layui ([CVE-2024-47075](https://github.com/layui/layui/security/advisories/GHSA-j827-6rgf-9629))\n", "id": "GHSA-m85w-3h95-hcf9", "modified": "2024-10-14T22:24:03Z", "published": "2024-10-14T20:02:21Z", "references": [ { "type": "WEB", "url": "https://github.com/withastro/astro/security/advisories/GHSA-m85w-3h95-hcf9" }, { "type": "ADVISORY", "url": "https://nvd.nist.gov/vuln/detail/CVE-2024-47885" }, { "type": "WEB", "url": "https://github.com/withastro/astro/commit/a4ffbfaa5cb460c12bd486fd75e36147f51d3e5e" }, { "type": "PACKAGE", "url": "https://github.com/withastro/astro" }, { "type": "WEB", "url": "https://github.com/withastro/astro/blob/7814a6cad15f06931f963580176d9b38aa7819f2/packages/astro/src/transitions/router.ts#L135-L156" } ], "schema_version": "1.4.0", "severity": [ { "score": "CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:H", "type": "CVSS_V3" } ], "summary": "DOM Clobbering Gadget found in astro\u0027s client-side router that leads to XSS" }
Sightings
Author | Source | Type | Date |
---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or seen somewhere by the user.
- Confirmed: The vulnerability is confirmed from an analyst perspective.
- Exploited: This vulnerability was exploited and seen by the user reporting the sighting.
- Patched: This vulnerability was successfully patched by the user reporting the sighting.
- Not exploited: This vulnerability was not exploited or seen by the user reporting the sighting.
- Not confirmed: The user expresses doubt about the veracity of the vulnerability.
- Not patched: This vulnerability was not successfully patched by the user reporting the sighting.