Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vitejs/vite
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.0.11
Choose a base ref
...
head repository: vitejs/vite
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.12
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Mar 24, 2025

  1. fix: fs raw query with query separators (#19702)

    sapphi-red committed Mar 24, 2025
    Copy the full SHA
    92ca12d View commit details
  2. release: v6.0.12

    sapphi-red committed Mar 24, 2025
    Copy the full SHA
    9d981f9 View commit details
6 changes: 6 additions & 0 deletions packages/vite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## <small>6.0.12 (2025-03-24)</small>

* fix: fs raw query with query separators (#19702) ([92ca12d](https://github.com/vitejs/vite/commit/92ca12dc79118bf66f2b32ff81ed09e0d0bd07ca)), closes [#19702](https://github.com/vitejs/vite/issues/19702)



## <small>6.0.11 (2025-01-21)</small>

* fix: `preview.allowedHosts` with specific values was not respected (#19246) ([aeb3ec8](https://github.com/vitejs/vite/commit/aeb3ec84a288d6be227a1284607f13428a4f14a1)), closes [#19246](https://github.com/vitejs/vite/issues/19246)
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite",
"version": "6.0.11",
"version": "6.0.12",
"type": "module",
"license": "MIT",
"author": "Evan You",
15 changes: 13 additions & 2 deletions packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ import { ensureServingAccess } from './static'
const debugCache = createDebugger('vite:cache')

const knownIgnoreList = new Set(['/', '/favicon.ico'])
const trailingQuerySeparatorsRE = /[?&]+$/

/**
* A middleware that short-circuits the middleware chain to serve cached transformed modules
@@ -169,9 +170,19 @@ export function transformMiddleware(
warnAboutExplicitPublicPathInUrl(url)
}

const urlWithoutTrailingQuerySeparators = url.replace(
trailingQuerySeparatorsRE,
'',
)
if (
(rawRE.test(url) || urlRE.test(url)) &&
!ensureServingAccess(url, server, res, next)
(rawRE.test(urlWithoutTrailingQuerySeparators) ||
urlRE.test(urlWithoutTrailingQuerySeparators)) &&
!ensureServingAccess(
urlWithoutTrailingQuerySeparators,
server,
res,
next,
)
) {
return
}
14 changes: 14 additions & 0 deletions playground/fs-serve/__tests__/fs-serve.spec.ts
Original file line number Diff line number Diff line change
@@ -96,6 +96,20 @@ describe.runIf(isServe)('main', () => {
expect(await page.textContent('.unsafe-fs-fetch-raw-status')).toBe('403')
})

test('unsafe fs fetch query 1', async () => {
expect(await page.textContent('.unsafe-fs-fetch-raw-query1')).toBe('')
expect(await page.textContent('.unsafe-fs-fetch-raw-query1-status')).toBe(
'403',
)
})

test('unsafe fs fetch query 2', async () => {
expect(await page.textContent('.unsafe-fs-fetch-raw-query2')).toBe('')
expect(await page.textContent('.unsafe-fs-fetch-raw-query2-status')).toBe(
'403',
)
})

test('unsafe fs fetch with special characters (#8498)', async () => {
expect(await page.textContent('.unsafe-fs-fetch-8498')).toBe('')
expect(await page.textContent('.unsafe-fs-fetch-8498-status')).toBe('404')
38 changes: 38 additions & 0 deletions playground/fs-serve/root/src/index.html
Original file line number Diff line number Diff line change
@@ -37,6 +37,10 @@ <h2>Unsafe /@fs/ Fetch</h2>
<pre class="unsafe-fs-fetch"></pre>
<pre class="unsafe-fs-fetch-raw-status"></pre>
<pre class="unsafe-fs-fetch-raw"></pre>
<pre class="unsafe-fs-fetch-raw-query1-status"></pre>
<pre class="unsafe-fs-fetch-raw-query1"></pre>
<pre class="unsafe-fs-fetch-raw-query2-status"></pre>
<pre class="unsafe-fs-fetch-raw-query2"></pre>
<pre class="unsafe-fs-fetch-8498-status"></pre>
<pre class="unsafe-fs-fetch-8498"></pre>
<pre class="unsafe-fs-fetch-8498-2-status"></pre>
@@ -209,6 +213,40 @@ <h2>Denied</h2>
console.error(e)
})

fetch(
joinUrlSegments(
base,
joinUrlSegments('/@fs/', ROOT) + '/unsafe.json?import&raw??',
),
)
.then((r) => {
text('.unsafe-fs-fetch-raw-query1-status', r.status)
return r.json()
})
.then((data) => {
text('.unsafe-fs-fetch-raw-query1', JSON.stringify(data))
})
.catch((e) => {
console.error(e)
})

fetch(
joinUrlSegments(
base,
joinUrlSegments('/@fs/', ROOT) + '/unsafe.json?import&raw?&',
),
)
.then((r) => {
text('.unsafe-fs-fetch-raw-query2-status', r.status)
return r.json()
})
.then((data) => {
text('.unsafe-fs-fetch-raw-query2', JSON.stringify(data))
})
.catch((e) => {
console.error(e)
})

// outside root with special characters #8498
fetch(
joinUrlSegments(