mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
parent
bfc5649b8d
commit
011bbca350
@ -0,0 +1,22 @@
|
||||
import { isBuild } from '../../../testUtils'
|
||||
|
||||
describe('main', () => {
|
||||
if (!isBuild) {
|
||||
test('**/deny/** should deny src/deny/deny.txt', async () => {
|
||||
const res = await page.request.fetch(
|
||||
new URL('/src/deny/deny.txt', viteTestUrl).href
|
||||
)
|
||||
expect(res.status()).toBe(403)
|
||||
})
|
||||
test('**/deny/** should deny src/deny/.deny', async () => {
|
||||
const res = await page.request.fetch(
|
||||
new URL('/src/deny/.deny', viteTestUrl).href
|
||||
)
|
||||
expect(res.status()).toBe(403)
|
||||
})
|
||||
} else {
|
||||
test('dummy test to make jest happy', async () => {
|
||||
// Your test suite must contain at least one test.
|
||||
})
|
||||
}
|
||||
})
|
@ -0,0 +1 @@
|
||||
module.exports = require('../../root/vite.config-deny')
|
@ -6,6 +6,9 @@
|
||||
"dev": "vite root",
|
||||
"build": "vite build root",
|
||||
"debug": "node --inspect-brk ../../vite/bin/vite",
|
||||
"preview": "vite preview"
|
||||
"preview": "vite preview",
|
||||
"dev:deny": "vite root --config ./root/vite.config-deny.js",
|
||||
"build:deny": "vite build root --config ./root/vite.config-deny.js",
|
||||
"preview:deny": "vite preview root --config ./root/vite.config-deny.js"
|
||||
}
|
||||
}
|
||||
|
1
packages/playground/fs-serve/root/src/deny/.deny
Normal file
1
packages/playground/fs-serve/root/src/deny/.deny
Normal file
@ -0,0 +1 @@
|
||||
.deny
|
1
packages/playground/fs-serve/root/src/deny/deny.txt
Normal file
1
packages/playground/fs-serve/root/src/deny/deny.txt
Normal file
@ -0,0 +1 @@
|
||||
deny
|
15
packages/playground/fs-serve/root/vite.config-deny.js
Normal file
15
packages/playground/fs-serve/root/vite.config-deny.js
Normal file
@ -0,0 +1,15 @@
|
||||
const path = require('path')
|
||||
const { defineConfig } = require('vite')
|
||||
|
||||
module.exports = defineConfig({
|
||||
server: {
|
||||
fs: {
|
||||
strict: true,
|
||||
allow: [path.resolve(__dirname, 'src')],
|
||||
deny: ['**/deny/**']
|
||||
}
|
||||
},
|
||||
define: {
|
||||
ROOT: JSON.stringify(path.dirname(__dirname).replace(/\\/g, '/'))
|
||||
}
|
||||
})
|
@ -156,7 +156,11 @@ export function serveRawFsMiddleware(
|
||||
}
|
||||
}
|
||||
|
||||
const _matchOptions = { matchBase: true, nocase: true }
|
||||
const _matchOptions = {
|
||||
matchBase: false,
|
||||
nocase: true,
|
||||
dot: true
|
||||
}
|
||||
|
||||
export function isFileServingAllowed(
|
||||
url: string,
|
||||
@ -166,8 +170,10 @@ export function isFileServingAllowed(
|
||||
|
||||
const file = fsPathFromUrl(url)
|
||||
|
||||
if (server.config.server.fs.deny.some((i) => isMatch(file, i, _matchOptions)))
|
||||
return false
|
||||
const deny = server.config.server.fs.deny.map((pattern) =>
|
||||
pattern.includes('/') ? pattern : `**/${pattern}`
|
||||
)
|
||||
if (deny.some((i) => isMatch(file, i, _matchOptions))) return false
|
||||
|
||||
if (server.moduleGraph.safeModulesPath.has(file)) return true
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user