Skip to content

Commit a26c87d

Browse files
committed
fix: fs deny for case insensitive
1 parent 494f36b commit a26c87d

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

packages/vite/src/node/server/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,10 @@ export async function createServer(
452452
_importGlobMap: new Map(),
453453
_forceOptimizeOnRestart: false,
454454
_pendingRequests: new Map(),
455-
_fsDenyGlob: picomatch(config.server.fs.deny, { matchBase: true })
455+
_fsDenyGlob: picomatch(config.server.fs.deny, {
456+
matchBase: true,
457+
nocase: true
458+
})
456459
}
457460

458461
server.transformIndexHtml = createDevHtmlTransformFn(server)

playground/fs-serve/__tests__/fs-serve.spec.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ describe.runIf(isServe)('main', () => {
9595
})
9696

9797
test('denied', async () => {
98-
expect(await page.textContent('.unsafe-dotenv')).toBe('404')
98+
expect(await page.textContent('.unsafe-dotenv')).toBe('403')
99+
})
100+
101+
test('denied EnV casing', async () => {
102+
// It is 403 in case insensitive system, 404 in others
103+
const code = await page.textContent('.unsafe-dotEnV-casing')
104+
expect(code === '403' || code === '404').toBeTruthy()
99105
})
100106
})
101107

playground/fs-serve/root/src/index.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ <h2>Nested Entry</h2>
4545

4646
<h2>Denied</h2>
4747
<pre class="unsafe-dotenv"></pre>
48+
<pre class="unsafe-dotEnV-casing"></pre>
4849

4950
<script type="module">
5051
import '../../entry'
@@ -202,14 +203,23 @@ <h2>Denied</h2>
202203
})
203204

204205
// .env, denied by default
205-
fetch('/@fs/' + ROOT + '/root/.env')
206+
fetch('/@fs/' + ROOT + '/root/src/.env')
206207
.then((r) => {
207208
text('.unsafe-dotenv', r.status)
208209
})
209210
.catch((e) => {
210211
console.error(e)
211212
})
212213

214+
// .env, for case insensitive file systems
215+
fetch('/@fs/' + ROOT + '/root/src/.EnV')
216+
.then((r) => {
217+
text('.unsafe-dotEnV-casing', r.status)
218+
})
219+
.catch((e) => {
220+
console.error(e)
221+
})
222+
213223
function text(sel, text) {
214224
document.querySelector(sel).textContent = text
215225
}

0 commit comments

Comments
 (0)