跪拜 Guibai
← All articles
Frontend · Vite

Vite Dev Server's CVSS 9.1 Critical Flaw Lets Attackers Inject Code via `--host`

By Flynt ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Because `--host` is a routine part of mobile preview and LAN collaboration, this flaw turns a standard dev workflow into a remote code execution surface. With no CVE number, automated scanners may not catch it, leaving exposed dev servers vulnerable until a manual upgrade happens.

Summary

Vite's dev server generates placeholder modules for browser-externalized Node builtins and unresolved optional peer dependencies. In affected versions, the request path that becomes a module ID is concatenated directly into a JavaScript template literal. An attacker can include `${}` in that ID, turning it into a live interpolation expression that executes when the module is parsed. A payload such as `x${(globalThis.INJ=1)}y` sets a global variable, and the same pattern can run any code in the victim's browser context.

The vulnerable versions span 4.0 to 8.3.6, covering all actively maintained majors. The exposure requires the developer to start the dev server with `--host 0.0.0.0` or set `server.host`, which is common for LAN debugging and real-device previews. A reproduction on Vite 7.3.7 confirmed the injection; the fixed 7.3.8 release moves the ID into a double-quoted string literal before interpolation, ensuring `${}` stays inert.

The advisory has no CVE number yet, so npm audit and Dependabot did not flag it immediately, and scanners relying on CVE/OSV feeds may miss it. No fix exists for 4.x and 5.x, so affected projects must upgrade to a patched version or stop exposing the dev server.

Takeaways
— The advisory GHSA-p4f5-76q4-ffq7 covers Vite versions 4.0 through 8.3.6, with fixed releases 8.3.7, 7.3.8, 6.4.6, and vite-plus 1.5.1.
— The vulnerability is in the dev server's virtual module generation for `__vite-browser-external` and `__vite-optional-peer-dep`, where the module ID is concatenated into a template literal without escaping.
— A crafted URL containing `${}` causes the expression to execute when the module is loaded, as demonstrated with `x${(globalThis.INJ=1)}y` setting the global variable.
— The default dev server on localhost is safe; the attack requires exposure via `--host` or `server.host`.
— The fixed version places the ID in a double-quoted string literal before interpolation, neutralizing the `${}` syntax.
— No CVE has been assigned, so npm audit and Dependabot did not immediately alert; scanners using CVE/OSV feeds may miss the advisory.
— When reproducing with curl, use `-g` (`--globoff`) to prevent curl's URL globbing from removing curly braces.
Conclusions

The absence of a CVE number creates a window where the vulnerability is invisible to automated dependency scanners, making human attention the only defense.

The reliance on `--host` for everyday tasks like phone previews and LAN pairing means many teams are unknowingly exposing a dev server that they assume is local-only.

The fix's technique of isolating user input in a double-quoted string before template interpolation is a simple, effective pattern that highlights how easy it is to slip into template literal injection.

Concepts & terms
CVSS 4.0
Common Vulnerability Scoring System, a framework for rating the severity of security vulnerabilities. A score of 9.1 out of 10 is considered critical.
Template literal injection
A security issue where user-controlled input is concatenated into a JavaScript template literal. If the input includes `${}` syntax, the enclosed expression is executed as code when the literal is evaluated.
Virtual module
In Vite, a module that is generated on the fly by the dev server rather than stored on disk. Virtual modules like `__vite-browser-external` create placeholder exports for Node builtins that aren't available in the browser.
URL globbing
A curl feature that expands curly braces `{...}` in URLs as a wildcard pattern. Use `-g` or `--globoff` to treat braces literally, which is necessary when a payload contains them.
From the discussion
Featured comments
组合搭配函数

This vulnerability is hidden deep enough. URL parameters can be spliced into template strings, and once --host is enabled, it's like leaving the door wide open. The reproduction and self-check conditions are all provided. After reading it, the only feeling is: upgrade the version immediately.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗