Skip to content

Commit

Permalink
chore(deps): update dependency vite to v5.0.5 [security] (#5325)
Browse files Browse the repository at this point in the history
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [vite](https://vitejs.dev)
([source](https://togithub.com/vitejs/vite/tree/HEAD/packages/vite)) |
[`5.0.4` -> `5.0.5`](https://renovatebot.com/diffs/npm/vite/5.0.4/5.0.5)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/vite/5.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/vite/5.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/vite/5.0.4/5.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/vite/5.0.4/5.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

### GitHub Vulnerability Alerts

####
[CVE-2023-49293](https://togithub.com/vitejs/vite/security/advisories/GHSA-92r3-m2mg-pj97)

### Summary
When Vite's HTML transformation is invoked manually via
`server.transformIndexHtml`, the original request URL is passed in
unmodified, and the `html` being transformed contains inline module
scripts (`<script type="module">...</script>`), it is possible to inject
arbitrary HTML into the transformed output by supplying a malicious URL
query string to `server.transformIndexHtml`.

### Impact
Only apps using `appType: 'custom'` and using the default Vite HTML
middleware are affected. The HTML entry must also contain an inline
script. The attack requires a user to click on a malicious URL while
running the dev server. Restricted files aren't exposed to the attacker.

### Patches
Fixed in [email protected], [email protected], [email protected]

### Details
Suppose `index.html` contains an inline module script:

```html
<script type="module">
  // Inline script
</script>
```

This script is transformed into a proxy script like

```html
<script type="module" src="/index.html?html-proxy&index=0.js"></script>
```

due to Vite's HTML plugin:


https://github.com/vitejs/vite/blob/7fd7c6cebfcad34ae7021ebee28f97b1f28ef3f3/packages/vite/src/node/plugins/html.ts#L429-L465

When `appType: 'spa' | 'mpa'`, Vite serves HTML itself, and
`htmlFallbackMiddleware` rewrites `req.url` to the canonical path of
`index.html`,


https://github.com/vitejs/vite/blob/73ef074b80fa7252e0c46a37a2c94ba8cba46504/packages/vite/src/node/server/middlewares/htmlFallback.ts#L44-L47

so the `url` passed to `server.transformIndexHtml` is `/index.html`.

However, if `appType: 'custom'`, HTML is served manually, and if
`server.transformIndexHtml` is called with the unmodified request URL
(as the SSR docs suggest), then the path of the transformed `html-proxy`
script varies with the request URL. For example, a request with path `/`
produces

```html
<script type="module" src="/@&#8203;id/__x00__/index.html?html-proxy&index=0.js"></script>
```

It is possible to abuse this behavior by crafting a request URL to
contain a malicious payload like

```
"></script><script>alert('boom')</script>
```

so a request to
http://localhost:5173/?%22%3E%3C/script%3E%3Cscript%3Ealert(%27boom%27)%3C/script%3E
produces HTML output like

```html
<script type="module" src="/@&#8203;id/__x00__/?"></script><script>alert("boom")</script>?html-proxy&index=0.js"></script>
```

which demonstrates XSS.

### PoC

- Example 1. Serving HTML from `vite dev` middleware with `appType:
'custom'`
- Go to
https://stackblitz.com/edit/vitejs-vite-9xhma4?file=main.js&terminal=dev-html
    - "Open in New Tab"
- Edit URL to set query string to
`?%22%3E%3C/script%3E%3Cscript%3Ealert(%27boom%27)%3C/script%3E` and
navigate
    - Witness XSS:
-
![image](https://user-images.githubusercontent.com/2456381/287434281-13757894-7a63-4a73-b1e9-d2b024c19d14.png)
- Example 2. Serving HTML from SSR-style Express server (Vite dev server
runs in middleware mode):
- Go to
https://stackblitz.com/edit/vitejs-vite-9xhma4?file=main.js&terminal=server
    - (Same steps as above)
- Example 3. Plain `vite dev` (this shows that vanilla `vite dev` is
_not_ vulnerable, provided `htmlFallbackMiddleware` is used)
- Go to
https://stackblitz.com/edit/vitejs-vite-9xhma4?file=main.js&terminal=dev
    - (Same steps as above)
    - You should _not_ see the alert box in this case

### Detailed Impact

This will probably predominantly affect [development-mode
SSR](https://vitejs.dev/guide/ssr#setting-up-the-dev-server), where
`vite.transformHtml` is called using the original `req.url`, per the
docs:


https://github.com/vitejs/vite/blob/7fd7c6cebfcad34ae7021ebee28f97b1f28ef3f3/docs/guide/ssr.md?plain=1#L114-L126

However, since this vulnerability affects `server.transformIndexHtml`,
the scope of impact may be higher to also include other ad-hoc calls to
`server.transformIndexHtml` from outside of Vite's own codebase.

My best guess at bisecting which versions are vulnerable involves the
following test script

```js
import fs from 'node:fs/promises';
import * as vite from 'vite';

const html = `
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <script type="module">
      // Inline script
    </script>
  </body>
</html>
`;
const server = await vite.createServer({ appType: 'custom' });
const transformed = await server.transformIndexHtml('/?%22%3E%3C/script%3E%3Cscript%3Ealert(%27boom%27)%3C/script%3E', html);
console.log(transformed);
await server.close();
```

and using it I was able to narrow down to #&#8203;13581. If this is
correct, then vulnerable Vite versions are 4.4.0-beta.2 and higher
(which includes 4.4.0).

---

### Release Notes

<details>
<summary>vitejs/vite (vite)</summary>

###
[`v5.0.5`](https://togithub.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small505-2023-12-04-small)

[Compare
Source](https://togithub.com/vitejs/vite/compare/v5.0.4...v5.0.5)

- fix: emit `vite:preloadError` for chunks without deps
([#&#8203;15203](https://togithub.com/vitejs/vite/issues/15203))
([d8001c5](https://togithub.com/vitejs/vite/commit/d8001c5)), closes
[#&#8203;15203](https://togithub.com/vitejs/vite/issues/15203)
- fix: esbuild glob import resolve error
([#&#8203;15140](https://togithub.com/vitejs/vite/issues/15140))
([676804d](https://togithub.com/vitejs/vite/commit/676804d)), closes
[#&#8203;15140](https://togithub.com/vitejs/vite/issues/15140)
- fix: json error with position
([#&#8203;15225](https://togithub.com/vitejs/vite/issues/15225))
([14be75f](https://togithub.com/vitejs/vite/commit/14be75f)), closes
[#&#8203;15225](https://togithub.com/vitejs/vite/issues/15225)
- fix: proxy html path should be encoded
([#&#8203;15223](https://togithub.com/vitejs/vite/issues/15223))
([5b85040](https://togithub.com/vitejs/vite/commit/5b85040)), closes
[#&#8203;15223](https://togithub.com/vitejs/vite/issues/15223)
- fix(deps): update all non-major dependencies
([#&#8203;15233](https://togithub.com/vitejs/vite/issues/15233))
([ad3adda](https://togithub.com/vitejs/vite/commit/ad3adda)), closes
[#&#8203;15233](https://togithub.com/vitejs/vite/issues/15233)
- fix(hmr): don't consider CSS dep as a circular dep
([#&#8203;15229](https://togithub.com/vitejs/vite/issues/15229))
([5f2cdec](https://togithub.com/vitejs/vite/commit/5f2cdec)), closes
[#&#8203;15229](https://togithub.com/vitejs/vite/issues/15229)
- feat: add '\*.mov' to client.d.ts
([#&#8203;15189](https://togithub.com/vitejs/vite/issues/15189))
([d93a211](https://togithub.com/vitejs/vite/commit/d93a211)), closes
[#&#8203;15189](https://togithub.com/vitejs/vite/issues/15189)
- feat(server): allow disabling built-in shortcuts
([#&#8203;15218](https://togithub.com/vitejs/vite/issues/15218))
([7fd7c6c](https://togithub.com/vitejs/vite/commit/7fd7c6c)), closes
[#&#8203;15218](https://togithub.com/vitejs/vite/issues/15218)
- chore: replace 'some' with 'includes' in resolveEnvPrefix
([#&#8203;15220](https://togithub.com/vitejs/vite/issues/15220))
([ee12f30](https://togithub.com/vitejs/vite/commit/ee12f30)), closes
[#&#8203;15220](https://togithub.com/vitejs/vite/issues/15220)
- chore: update the website url for homepage in package.json
([#&#8203;15181](https://togithub.com/vitejs/vite/issues/15181))
([282bd8f](https://togithub.com/vitejs/vite/commit/282bd8f)), closes
[#&#8203;15181](https://togithub.com/vitejs/vite/issues/15181)
- chore: update vitest to 1.0.0-beta.6
([#&#8203;15194](https://togithub.com/vitejs/vite/issues/15194))
([2fce647](https://togithub.com/vitejs/vite/commit/2fce647)), closes
[#&#8203;15194](https://togithub.com/vitejs/vite/issues/15194)
- refactor: make HMR agnostic to environment
([#&#8203;15179](https://togithub.com/vitejs/vite/issues/15179))
([0571b7c](https://togithub.com/vitejs/vite/commit/0571b7c)), closes
[#&#8203;15179](https://togithub.com/vitejs/vite/issues/15179)
- refactor: use dedicated regex methods
([#&#8203;15228](https://togithub.com/vitejs/vite/issues/15228))
([0348137](https://togithub.com/vitejs/vite/commit/0348137)), closes
[#&#8203;15228](https://togithub.com/vitejs/vite/issues/15228)
- perf: remove debug only prettifyUrl call
([#&#8203;15204](https://togithub.com/vitejs/vite/issues/15204))
([73e971f](https://togithub.com/vitejs/vite/commit/73e971f)), closes
[#&#8203;15204](https://togithub.com/vitejs/vite/issues/15204)
- perf: skip computing sourceRoot in injectSourcesContent
([#&#8203;15207](https://togithub.com/vitejs/vite/issues/15207))
([1df1fd1](https://togithub.com/vitejs/vite/commit/1df1fd1)), closes
[#&#8203;15207](https://togithub.com/vitejs/vite/issues/15207)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "" (UTC), Automerge - At any time (no
schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/SAP/ui5-webcomponents-react).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44MS4zIiwidXBkYXRlZEluVmVyIjoiMzcuODEuMyIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
renovate[bot] authored Dec 6, 2023
1 parent a1e89e4 commit e9f5db1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions examples/vite-ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18694,7 +18694,7 @@ __metadata:
languageName: node
linkType: hard

"postcss@npm:^8.4.25, postcss@npm:^8.4.27, postcss@npm:^8.4.31, postcss@npm:^8.4.5":
"postcss@npm:^8.4.25, postcss@npm:^8.4.27, postcss@npm:^8.4.32, postcss@npm:^8.4.5":
version: 8.4.32
resolution: "postcss@npm:8.4.32"
dependencies:
Expand Down Expand Up @@ -22627,8 +22627,8 @@ __metadata:
linkType: hard

"vite@npm:^4.4.9":
version: 4.5.0
resolution: "vite@npm:4.5.0"
version: 4.5.1
resolution: "vite@npm:4.5.1"
dependencies:
esbuild: "npm:^0.18.10"
fsevents: "npm:~2.3.2"
Expand Down Expand Up @@ -22662,17 +22662,17 @@ __metadata:
optional: true
bin:
vite: bin/vite.js
checksum: 7e21e9e4b80656ae5ee61e8c5edb5e8f589139c2b22c43e89d054c65a0194f1c1ef066fbc770204173c7eb244c798265042f988adda5880ad74337a053b28b7f
checksum: 352a94b13f793e4bcbc424d680a32507343223eeda8917fde0f23c1fa1ba3db7c806dade8461ca5cfb270154ddb8895a219fdd4384519fe9b8e46d1cf491a890
languageName: node
linkType: hard

"vite@npm:^5.0.0":
version: 5.0.4
resolution: "vite@npm:5.0.4"
version: 5.0.5
resolution: "vite@npm:5.0.5"
dependencies:
esbuild: "npm:^0.19.3"
fsevents: "npm:~2.3.3"
postcss: "npm:^8.4.31"
postcss: "npm:^8.4.32"
rollup: "npm:^4.2.0"
peerDependencies:
"@types/node": ^18.0.0 || >=20.0.0
Expand Down Expand Up @@ -22702,7 +22702,7 @@ __metadata:
optional: true
bin:
vite: bin/vite.js
checksum: 67a0df248af042e75b1ecbf20098096df80a1068a832c5c964a20d7c06853e12b7310989c3c273cb88a9a3a37f4bada0a2115018b36df0fc09a6b6dba9a7d5b5
checksum: 22fbaacbc87eff7d1de46104880c5d269d3bb2964957e9d13edaac819e6a90b5ce2567b5d0ba8c92a7bd5bcf0412ae7d22ce958047490931fbb466b1908ff17c
languageName: node
linkType: hard

Expand Down

0 comments on commit e9f5db1

Please sign in to comment.