mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
fix: fs.deny
with globs with directories (#16250)
This commit is contained in:
parent
7a2791ce17
commit
ba5269cca8
@ -685,10 +685,19 @@ export async function _createServer(
|
||||
_importGlobMap: new Map(),
|
||||
_forceOptimizeOnRestart: false,
|
||||
_pendingRequests: new Map(),
|
||||
_fsDenyGlob: picomatch(config.server.fs.deny, {
|
||||
matchBase: true,
|
||||
nocase: true,
|
||||
}),
|
||||
_fsDenyGlob: picomatch(
|
||||
// matchBase: true does not work as it's documented
|
||||
// https://github.com/micromatch/picomatch/issues/89
|
||||
// convert patterns without `/` on our side for now
|
||||
config.server.fs.deny.map((pattern) =>
|
||||
pattern.includes('/') ? pattern : `**/${pattern}`,
|
||||
),
|
||||
{
|
||||
matchBase: false,
|
||||
nocase: true,
|
||||
dot: true,
|
||||
},
|
||||
),
|
||||
_shortcutsOptions: undefined,
|
||||
}
|
||||
|
||||
|
17
playground/fs-serve/__tests__/deny/fs-serve-deny.spec.ts
Normal file
17
playground/fs-serve/__tests__/deny/fs-serve-deny.spec.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import { isServe, page, viteTestUrl } from '~utils'
|
||||
|
||||
describe.runIf(isServe)('main', () => {
|
||||
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)
|
||||
})
|
||||
})
|
@ -10,6 +10,9 @@
|
||||
"preview": "vite preview root",
|
||||
"dev:base": "vite root --config ./root/vite.config-base.js",
|
||||
"build:base": "vite build root --config ./root/vite.config-base.js",
|
||||
"preview:base": "vite preview root --config ./root/vite.config-base.js"
|
||||
"preview:base": "vite preview root --config ./root/vite.config-base.js",
|
||||
"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
playground/fs-serve/root/src/deny/.deny
Normal file
1
playground/fs-serve/root/src/deny/.deny
Normal file
@ -0,0 +1 @@
|
||||
.deny
|
1
playground/fs-serve/root/src/deny/deny.txt
Normal file
1
playground/fs-serve/root/src/deny/deny.txt
Normal file
@ -0,0 +1 @@
|
||||
deny
|
22
playground/fs-serve/root/vite.config-deny.js
Normal file
22
playground/fs-serve/root/vite.config-deny.js
Normal file
@ -0,0 +1,22 @@
|
||||
import path from 'node:path'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
main: path.resolve(__dirname, 'src/index.html'),
|
||||
},
|
||||
},
|
||||
},
|
||||
server: {
|
||||
fs: {
|
||||
strict: true,
|
||||
allow: [path.resolve(__dirname, 'src')],
|
||||
deny: ['**/deny/**'],
|
||||
},
|
||||
},
|
||||
define: {
|
||||
ROOT: JSON.stringify(path.dirname(__dirname).replace(/\\/g, '/')),
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue
Block a user