Skip to content

fix: fs raw query #18112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: ensureServingAccess at middleware level
  • Loading branch information
patak-dev committed Sep 16, 2024
commit 42345adc92a21b35335fd31e3e01eccfb0dea5fe
5 changes: 0 additions & 5 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
import { DEFAULT_ASSETS_INLINE_LIMIT, FS_PREFIX } from '../constants'
import { cleanUrl, withTrailingSlash } from '../../shared/utils'
import type { Environment } from '../environment'
import { isFileServingAllowed } from '../server/middlewares/static'

// referenceId is base64url but replaces - with $
export const assetUrlRE = /__VITE_ASSET__([\w$]+)__(?:\$_(.*?)__)?/g
Expand Down Expand Up @@ -168,10 +167,6 @@ export function assetPlugin(config: ResolvedConfig): Plugin {

// raw requests, read from disk
if (rawRE.test(id)) {
if (config.command === 'serve' && !isFileServingAllowed(config, id)) {
// Let the load fallback handle the fs restriction error
return
}
const file = checkPublicFile(id, config) || cleanUrl(id)
this.addWatchFile(file)
// raw query, read file and return as string
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export function isFileLoadingAllowed(
return false
}

function ensureServingAccess(
export function ensureServingAccess(
url: string,
server: ViteDevServer,
res: ServerResponse,
Expand Down
9 changes: 9 additions & 0 deletions packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isJSRequest,
normalizePath,
prettifyUrl,
rawRE,
removeImportQuery,
removeTimestampQuery,
urlRE,
Expand All @@ -34,6 +35,7 @@ import {
import { ERR_CLOSED_SERVER } from '../pluginContainer'
import { cleanUrl, unwrapId, withTrailingSlash } from '../../../shared/utils'
import { NULL_BYTE_PLACEHOLDER } from '../../../shared/constants'
import { ensureServingAccess } from './static'

const debugCache = createDebugger('vite:cache')

Expand Down Expand Up @@ -164,6 +166,13 @@ export function transformMiddleware(
warnAboutExplicitPublicPathInUrl(url)
}

if (
(rawRE.test(url) || urlRE.test(url)) &&
!ensureServingAccess(url, server, res, next)
) {
return
}

if (
isJSRequest(url) ||
isImportRequest(url) ||
Expand Down
Loading