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 @@ -685,10 +685,19 @@ export async function _createServer(
685685 _importGlobMap : new Map ( ) ,
686686 _forceOptimizeOnRestart : false ,
687687 _pendingRequests : new Map ( ) ,
688- _fsDenyGlob : picomatch ( config . server . fs . deny , {
689- matchBase : true ,
690- nocase : true ,
691- } ) ,
688+ _fsDenyGlob : picomatch (
689+ // matchBase: true does not work as it's documented
690+ // https://github.com/micromatch/picomatch/issues/89
691+ // convert patterns without `/` on our side for now
692+ config . server . fs . deny . map ( ( pattern ) =>
693+ pattern . includes ( '/' ) ? pattern : `**/${ pattern } ` ,
694+ ) ,
695+ {
696+ matchBase : false ,
697+ nocase : true ,
698+ dot : true ,
699+ } ,
700+ ) ,
692701 _shortcutsOptions : undefined ,
693702 }
694703
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