Commit 813ddd6 1 parent 28923fb commit 813ddd6 Copy full SHA for 813ddd6
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 @@ -100,7 +100,7 @@ export function serveStaticMiddleware(
100
100
return next ( )
101
101
}
102
102
103
- const url = new URL ( req . url ! , 'http://example.com' )
103
+ const url = new URL ( req . url ! . replace ( / ^ \/ + / , '/' ) , 'http://example.com' )
104
104
const pathname = decodeURIComponent ( url . pathname )
105
105
106
106
// apply aliases to static requests as well
@@ -153,7 +153,7 @@ export function serveRawFsMiddleware(
153
153
154
154
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
155
155
return function viteServeRawFsMiddleware ( req , res , next ) {
156
- const url = new URL ( req . url ! , 'http://example.com' )
156
+ const url = new URL ( req . url ! . replace ( / ^ \/ + / , '/' ) , 'http://example.com' )
157
157
// In some cases (e.g. linked monorepos) files outside of root will
158
158
// reference assets that are also out of served root. In such cases
159
159
// 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