Summary
Vite's development server exposes a WebSocket endpoint that can be abused to fetch arbitrary local files as JavaScript strings when Origin checks are missing or bypassed.
If an attacker can connect to the dev server's WebSocket without a valid Origin header, they may invoke internal module-fetching logic and read files from the server's filesystem outside the normal HTTP access controls.
Affected context
This vulnerability affects Vite dev server deployments running affected versions where:
- The Vite dev server is reachable from an attacker's environment (e.g., exposed to a broader network or internet-facing during development).
- WebSocket connections to the dev server can be established without a strict Origin header check.
- The internal
vite:invokeWebSocket event andfetchModulepathway are available during development.
In such setups, the WebSocket-based file loading path is not subject to the same filesystem access controls enforced on HTTP requests.
Exploit preconditions
- Attack surface: Vite dev server's WebSocket endpoint used for development tooling.
- Required access: Network-level ability to reach the dev server and open a WebSocket connection (e.g., from the same LAN, VPN, or internet if misconfigured).
- Authentication / Origin checks: Ability to connect without a restrictive Origin header, or in an environment where Origin validation is absent, misconfigured, or bypassed.
- Trigger point: Sending a crafted
vite:invokeWebSocket message that callsfetchModulewith afile://...URL combined with?rawor?inline. - Why exploitation is possible: The WebSocket-based module fetch logic bypasses the HTTP-layer access control (such as
server.fs.allow) and treats attacker-controlled file paths as trusted module input, returning file contents as JavaScript strings.
Why this happens
The root cause lies in a mismatch between security controls on different code paths that access the filesystem.
Vite enforces filesystem restrictions on HTTP requests (for example, using server.fs.allow) but failed to apply equivalent checks to the WebSocket-driven fetchModule pathway.
Because the WebSocket handler trusted connections that lacked a validated Origin header, it exposed internal functionality (vite:invoke) that could be steered to load arbitrary local resources via file:// URLs with special query parameters (?raw or ?inline).
This design issue maps to CWE-200: Exposure of Sensitive Information to an Unauthorized Actor due to unintended data disclosure, and relates to CWE-306: Missing Authentication for Critical Function because a privileged file-access capability was reachable without appropriate access control when invoked over WebSocket.
Potential impact
- Disclosure of arbitrary local files readable by the dev server process, including configuration files or code not normally exposed over HTTP.
- Exposure of secrets stored in local files, such as API keys, tokens, or environment-specific credentials.
- Leakage of application source code or proprietary logic from the developer's machine or build environment.
- Increased risk of follow-on attacks, such as credential reuse or targeted exploitation based on revealed configuration details.
General mitigation guidance
Effective mitigation focuses on tightening trust boundaries around the dev server and aligning security checks across all access paths:
- Restrict dev server exposure to trusted networks only (e.g., bind to localhost or development VPN) so untrusted clients cannot reach the WebSocket endpoint.
- Enforce strict Origin validation and, where applicable, additional authentication or tokens for dev tooling WebSocket connections.
- Harmonize access control logic so that any file access—whether via HTTP or WebSocket—passes through the same authorization and filesystem-allowlist checks.
- Minimize secrets and sensitive assets on machines running the dev server, or store them outside paths accessible to development tooling.
- Apply least-privilege filesystem practices for development environments, ensuring the dev process does not needlessly have read access to sensitive directories.
How teams detect issues like this
Detection can leverage both code-centric and environment-centric approaches:
- Static analysis / code review:
- Look for WebSocket handlers that expose internal commands (such as
vite:invoke-style RPC) without consistent access control or Origin validation. - Flag code paths that open or fetch local files (
file://or filesystem APIs) without passing through a common authorization layer. - Identify logic that treats dev-only APIs as implicitly trusted without environmental checks (e.g., assuming all clients are local).
- Runtime and configuration monitoring:
- Monitor dev server logs for unusual WebSocket connections from unexpected IPs or with missing/abnormal Origin headers.
- Track use of internal invocation events that resemble module-fetching commands originating from non-standard clients.
- Use network policies or local firewalls to detect and alert on external access attempts to dev server ports.
- Automated tooling:
- Incorporate SAST/DAST tools that understand WebSocket flows and can verify that critical operations require appropriate authentication and are subject to the same access checks as HTTP endpoints.

