File tree 7 files changed +59
-5
lines changed
packages/vite/src/node/server
7 files changed +59
-5
lines changed Original file line number Diff line number Diff line change @@ -452,10 +452,19 @@ export async function createServer(
452
452
_importGlobMap : new Map ( ) ,
453
453
_forceOptimizeOnRestart : false ,
454
454
_pendingRequests : new Map ( ) ,
455
- _fsDenyGlob : picomatch ( config . server . fs . deny , {
456
- matchBase : true ,
457
- nocase : true
458
- } )
455
+ _fsDenyGlob : picomatch (
456
+ // matchBase: true does not work as it's documented
457
+ // https://github.com/micromatch/picomatch/issues/89
458
+ // convert patterns without `/` on our side for now
459
+ config . server . fs . deny . map ( ( pattern ) =>
460
+ pattern . includes ( '/' ) ? pattern : `**/${ pattern } `
461
+ ) ,
462
+ {
463
+ matchBase : false ,
464
+ nocase : true ,
465
+ dot : true
466
+ }
467
+ )
459
468
}
460
469
461
470
server . transformIndexHtml = createDevHtmlTransformFn ( server )
Original file line number Diff line number Diff line change
1
+ import { describe , expect , test } from 'vitest'
2
+ import { isServe , page , viteTestUrl } from '~utils'
3
+
4
+ describe . runIf ( isServe ) ( 'main' , ( ) => {
5
+ test ( '**/deny/** should deny src/deny/deny.txt' , async ( ) => {
6
+ const res = await page . request . fetch (
7
+ new URL ( '/src/deny/deny.txt' , viteTestUrl ) . href
8
+ )
9
+ expect ( res . status ( ) ) . toBe ( 403 )
10
+ } )
11
+ test ( '**/deny/** should deny src/deny/.deny' , async ( ) => {
12
+ const res = await page . request . fetch (
13
+ new URL ( '/src/deny/.deny' , viteTestUrl ) . href
14
+ )
15
+ expect ( res . status ( ) ) . toBe ( 403 )
16
+ } )
17
+ } )
Original file line number Diff line number Diff line change
1
+ module . exports = require ( '../../root/vite.config-deny' )
Original file line number Diff line number Diff line change 6
6
"dev" : " vite root" ,
7
7
"build" : " vite build root" ,
8
8
"debug" : " node --inspect-brk ../../packages/vite/bin/vite" ,
9
- "preview" : " vite preview root"
9
+ "preview" : " vite preview root" ,
10
+ "dev:deny" : " vite root --config ./root/vite.config-deny.js" ,
11
+ "build:deny" : " vite build root --config ./root/vite.config-deny.js" ,
12
+ "preview:deny" : " vite preview root --config ./root/vite.config-deny.js"
10
13
}
11
14
}
Original file line number Diff line number Diff line change
1
+ .deny
Original file line number Diff line number Diff line change
1
+ deny
Original file line number Diff line number Diff line change
1
+ import path from 'node:path'
2
+ import { defineConfig } from 'vite'
3
+
4
+ export default defineConfig ( {
5
+ build : {
6
+ rollupOptions : {
7
+ input : {
8
+ main : path . resolve ( __dirname , 'src/index.html' )
9
+ }
10
+ }
11
+ } ,
12
+ server : {
13
+ fs : {
14
+ strict : true ,
15
+ allow : [ path . resolve ( __dirname , 'src' ) ] ,
16
+ deny : [ '**/deny/**' ]
17
+ }
18
+ } ,
19
+ define : {
20
+ ROOT : JSON . stringify ( path . dirname ( __dirname ) . replace ( / \\ / g, '/' ) )
21
+ }
22
+ } )
You can’t perform that action at this time.
0 commit comments