File tree 4 files changed +38
-3
lines changed
packages/vite/src/node/server/middlewares
playground/assets-sanitize
4 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ export function serveStaticMiddleware(
78
78
return next ( )
79
79
}
80
80
81
- const url = new URL ( req . url ! , 'http://example.com' )
81
+ const url = new URL ( req . url ! . replace ( / ^ \/ + / , '/' ) , 'http://example.com' )
82
82
const pathname = decodeURIComponent ( url . pathname )
83
83
84
84
// apply aliases to static requests as well
@@ -125,7 +125,7 @@ export function serveRawFsMiddleware(
125
125
126
126
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
127
127
return function viteServeRawFsMiddleware ( req , res , next ) {
128
- const url = new URL ( req . url ! , 'http://example.com' )
128
+ const url = new URL ( req . url ! . replace ( / ^ \/ + / , '/' ) , 'http://example.com' )
129
129
// In some cases (e.g. linked monorepos) files outside of root will
130
130
// reference assets that are also out of served root. In such cases
131
131
// the paths are rewritten to `/@fs/` prefixed paths and must be served by
Original file line number Diff line number Diff line change
1
+ KEY = unsafe
Original file line number Diff line number Diff line change @@ -25,3 +25,8 @@ if (!isBuild) {
25
25
expect ( Object . keys ( manifest ) . length ) . toBe ( 3 ) // 2 svg, 1 index.js
26
26
} )
27
27
}
28
+
29
+ test . runIf ( ! isBuild ) ( 'denied .env' , async ( ) => {
30
+ expect ( await page . textContent ( '.unsafe-dotenv' ) ) . toBe ( '403' )
31
+ expect ( await page . textContent ( '.unsafe-dotenv-double-slash' ) ) . toBe ( '403' )
32
+ } )
Original file line number Diff line number Diff line change 6
6
margin-bottom : 1rem ;
7
7
}
8
8
</ style >
9
- < h1 > test elements below should show circles and their url</ h1 >
9
+ < h3 > test elements below should show circles and their url</ h3 >
10
10
< div class ="test-el plus-circle "> </ div >
11
11
< div class ="test-el underscore-circle "> </ div >
12
+
13
+ < h3 > Denied .env</ h3 >
14
+ < div class ="unsafe-dotenv "> </ div >
15
+ < div class ="unsafe-dotenv-double-slash "> </ div >
16
+
17
+ < script type ="module ">
18
+ // .env, denied by default. See fs-serve playground for other fs tests
19
+ // these checks ensure that a project without a custom root respects fs.deny
20
+
21
+ fetch ( '/.env' )
22
+ . then ( ( r ) => {
23
+ text ( '.unsafe-dotenv' , r . status )
24
+ } )
25
+ . catch ( ( e ) => {
26
+ console . error ( e )
27
+ } )
28
+
29
+ fetch ( window . location + '/.env' )
30
+ . then ( ( r ) => {
31
+ text ( '.unsafe-dotenv-double-slash' , r . status )
32
+ } )
33
+ . catch ( ( e ) => {
34
+ console . error ( e )
35
+ } )
36
+
37
+ function text ( el , text ) {
38
+ document . querySelector ( el ) . textContent = text
39
+ }
40
+ </ script >
You can’t perform that action at this time.
0 commit comments