Skip to content

Commit 64e2467

Browse files
authored
fix(wasm): reject .wasm outside server.fs (#23914)
1 parent cc9bc21 commit 64e2467

5 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎packages/vite/src/node/server/middlewares/transform.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const urlRE = /[?&]url\b/
5353
const rawRE = /[?&]raw\b/
5454
const inlineRE = /[?&]inline\b/
5555
const svgRE = /\.svg\b/
56+
const wasmRE = /(?<![?#].*)\.wasm$/
5657
const wasmInstanceRE = /[?&]vite-wasm-instance(?:&|$)/
5758

5859
export function isServerAccessDeniedForTransform(
@@ -64,6 +65,7 @@ export function isServerAccessDeniedForTransform(
6465
urlRE.test(id) ||
6566
inlineRE.test(id) ||
6667
svgRE.test(id) ||
68+
wasmRE.test(id) ||
6769
wasmInstanceRE.test(id)
6870
) {
6971
return (

‎playground/fs-serve/__tests__/commonTests.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ export function tests() {
127127
disableVariants: [''],
128128
},
129129

130+
{
131+
name: 'unsafe WASM import',
132+
testId: 'unsafe-wasm-import',
133+
content: /403 Restricted/,
134+
status: '403',
135+
},
136+
130137
{
131138
name: 'unsafe fetch',
132139
testId: 'unsafe',

‎playground/fs-serve/root/matrixTestResultPlugin.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const testIds = [
99
'safe-subdir-special-characters2',
1010
'safe-imported',
1111
'safe-imported-query',
12+
'unsafe-wasm-import',
1213
'unsafe',
1314
'unsafe-json',
1415
'unsafe-html',

‎playground/fs-serve/root/src/index.html‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ <h2>Safe Module Path Access Isolation</h2>
8383
// imported before with query
8484
{ testId: 'safe-imported-query', path: '/safe.json?query' },
8585

86+
{
87+
testId: 'unsafe-wasm-import',
88+
path: '/root/unsafe.wasm?import',
89+
},
90+
8691
// outside of allowed dir
8792
{ testId: 'unsafe', path: '/root/unsafe.txt' },
8893
// outside of allowed dir and root
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KEY=unsafe

0 commit comments

Comments
 (0)