File tree Expand file tree Collapse file tree 6 files changed +58
-5
lines changed
packages/vite/src/node/server Expand file tree Collapse file tree 6 files changed +58
-5
lines changed Original file line number Diff line number Diff line change @@ -509,10 +509,19 @@ export async function _createServer(
509509 _importGlobMap : new Map ( ) ,
510510 _forceOptimizeOnRestart : false ,
511511 _pendingRequests : new Map ( ) ,
512- _fsDenyGlob : picomatch ( config . server . fs . deny , {
513- matchBase : true ,
514- nocase : true ,
515- } ) ,
512+ _fsDenyGlob : picomatch (
513+ // matchBase: true does not work as it's documented
514+ // https://github.com/micromatch/picomatch/issues/89
515+ // convert patterns without `/` on our side for now
516+ config . server . fs . deny . map ( ( pattern ) =>
517+ pattern . includes ( '/' ) ? pattern : `**/${ pattern } ` ,
518+ ) ,
519+ {
520+ matchBase : false ,
521+ nocase : true ,
522+ dot : true ,
523+ } ,
524+ ) ,
516525 _shortcutsOptions : undefined ,
517526 }
518527
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 1010 "preview" : " vite preview root" ,
1111 "dev:base" : " vite root --config ./root/vite.config-base.js" ,
1212 "build:base" : " vite build root --config ./root/vite.config-base.js" ,
13- "preview:base" : " vite preview root --config ./root/vite.config-base.js"
13+ "preview:base" : " vite preview root --config ./root/vite.config-base.js" ,
14+ "dev:deny" : " vite root --config ./root/vite.config-deny.js" ,
15+ "build:deny" : " vite build root --config ./root/vite.config-deny.js" ,
16+ "preview:deny" : " vite preview root --config ./root/vite.config-deny.js"
1417 }
1518}
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