Commit c12fc82
fix: verify module identity in cache protocol to prevent stale modules
The module runner's `urlToIdModuleMap` caches modules by URL. When a
bare specifier (e.g., `@azure/core-lro`) is used as the URL, the first
resolved version is cached and served to all subsequent importers, even
if they should receive a different physical package.
Additionally, the `{ cache: true }` protocol between the module runner
and server had no identity verification. The server confirms a module
was transformed without checking if the client's cached module matches
the server's resolved module.
Fix:
- Server now includes the resolved module ID in `{ cache: true }`
responses via the new optional `id` field on `CachedFetchResult`.
- Client verifies that its cached module ID matches the server's. On
mismatch, the client refetches the module without the cache flag.
This prevents silent data corruption when multiple versions of a
dependency exist in a monorepo with nested `node_modules`.
Fixes #22079
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 6daa10f commit c12fc82
File tree
3 files changed
+28
-2
lines changed- packages/vite/src
- module-runner
- node/ssr
3 files changed
+28
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
312 | 331 | | |
313 | 332 | | |
314 | 333 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
| |||
0 commit comments