Skip to content

Commit 2136771

Browse files
authored
feat!: server fs strict by default (#5341)
1 parent 1a15460 commit 2136771

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

docs/config/index.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,18 +542,16 @@ createServer()
542542

543543
### server.fs.strict
544544

545-
- **Experimental**
546545
- **Type:** `boolean`
547-
- **Default:** `false` (will change to `true` in future versions)
546+
- **Default:** `true` (enabled by default since Vite 2.7)
548547

549548
Restrict serving files outside of workspace root.
550549

551550
### server.fs.allow
552551

553-
- **Experimental**
554552
- **Type:** `string[]`
555553

556-
Restrict files that could be served via `/@fs/`. When `server.fs.strict` is set to `true`, accessing files outside this directory list will result in a 403.
554+
Restrict files that could be served via `/@fs/`. When `server.fs.strict` is set to `true`, accessing files outside this directory list that aren't imported from an allowed file will result in a 403.
557555

558556
Vite will search for the root of the potential workspace and use it as default. A valid workspace met the following conditions, otherwise will fallback to the [project root](/guide/#index-html-and-project-root).
559557

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,15 @@ export interface FileSystemServeOptions {
148148
* Set to `false` to disable the warning
149149
* Default to false at this moment, will enabled by default in the future versions.
150150
*
151-
* @experimental
152-
* @default undefined
151+
* @default true
153152
*/
154-
strict?: boolean | undefined
153+
strict?: boolean
155154

156155
/**
157156
* Restrict accessing files outside the allowed directories.
158157
*
159158
* Accepts absolute path or a path relative to project root.
160159
* Will try to search up for workspace root by default.
161-
*
162-
* @experimental
163160
*/
164161
allow?: string[]
165162

@@ -717,8 +714,7 @@ export function resolveServerOptions(
717714
}
718715

719716
server.fs = {
720-
// TODO: make strict by default
721-
strict: server.fs?.strict,
717+
strict: server.fs?.strict ?? true,
722718
allow: allowDirs,
723719
deny
724720
}

packages/vite/src/node/server/middlewares/static.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ export function isFileServingAllowed(
137137
url: string,
138138
server: ViteDevServer
139139
): boolean {
140-
// explicitly disabled
141-
if (server.config.server.fs.strict === false) return true
140+
if (!server.config.server.fs.strict) return true
142141

143142
const cleanedUrl = cleanUrl(url)
144143
const file = ensureLeadingSlash(normalizePath(cleanedUrl))
@@ -151,18 +150,6 @@ export function isFileServingAllowed(
151150
if (server.config.server.fs.allow.some((i) => file.startsWith(i + '/')))
152151
return true
153152

154-
if (!server.config.server.fs.strict) {
155-
if (isFileReadable(cleanedUrl)) {
156-
server.config.logger.warnOnce(`Unrestricted file system access to "${url}"`)
157-
server.config.logger.warnOnce(
158-
`For security concerns, accessing files outside of serving allow list will ` +
159-
`be restricted by default in the future version of Vite. ` +
160-
`Refer to https://vitejs.dev/config/#server-fs-allow for more details.`
161-
)
162-
}
163-
return true
164-
}
165-
166153
return false
167154
}
168155

0 commit comments

Comments
 (0)