Skip to content
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

chore: Enable vite.server.fs.strict internally by default #1842

Merged
merged 3 commits into from Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-grapes-cover.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Enable Vite's server.fs.strict by default
10 changes: 10 additions & 0 deletions documentation/faq/90-fs-strict.md
@@ -0,0 +1,10 @@
---
question: "Internal server error: The request url [...] is outside of Vite serving allow list"
---

For security reasons, Vite has been configured to only allow filesystem access when the request file fulfils one of these requirements:
- Within workspace root
- Within the listed `server.fs.allow` exceptions
- Part of the dependency graph of your application code

Refer to Vite documentation for [`server.fs.allow`](https://vitejs.dev/config/#server-fs-allow) for configuration and more details.
39 changes: 36 additions & 3 deletions packages/kit/src/core/build/index.js
Expand Up @@ -134,8 +134,19 @@ async function build_client({
/** @type {any} */
const user_config = config.kit.vite();

const default_config = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's a ticket anywhere to track turning this on by default in Vite, but it could be good to add a link to it with a TODO to remove this after it's enabled

server: {
fs: {
strict: true
}
}
};

// don't warn on overriding defaults
const [modified_user_config] = deep_merge(default_config, user_config);

/** @type {[any, string[]]} */
const [merged_config, conflicts] = deep_merge(user_config, {
const [merged_config, conflicts] = deep_merge(modified_user_config, {
configFile: false,
root: cwd,
base,
Expand Down Expand Up @@ -408,8 +419,19 @@ async function build_server(
/** @type {any} */
const user_config = config.kit.vite();

const default_config = {
server: {
fs: {
strict: true
}
}
};

// don't warn on overriding defaults
const [modified_user_config] = deep_merge(default_config, user_config);

/** @type {[any, string[]]} */
const [merged_config, conflicts] = deep_merge(user_config, {
const [merged_config, conflicts] = deep_merge(modified_user_config, {
configFile: false,
root: cwd,
base,
Expand Down Expand Up @@ -515,8 +537,19 @@ async function build_service_worker(
/** @type {any} */
const user_config = config.kit.vite();

const default_config = {
server: {
fs: {
strict: true
}
}
};

// don't warn on overriding defaults
const [modified_user_config] = deep_merge(default_config, user_config);

/** @type {[any, string[]]} */
const [merged_config, conflicts] = deep_merge(user_config, {
const [merged_config, conflicts] = deep_merge(modified_user_config, {
configFile: false,
root: cwd,
base,
Expand Down
13 changes: 12 additions & 1 deletion packages/kit/src/core/dev/index.js
Expand Up @@ -82,15 +82,26 @@ class Watcher extends EventEmitter {
/** @type {any} */
const user_config = (this.config.kit.vite && this.config.kit.vite()) || {};

const default_config = {
server: {
fs: {
strict: true
}
}
};

/** @type {(req: import("http").IncomingMessage, res: import("http").ServerResponse) => void} */
let handler = (req, res) => {};

this.server = await get_server(this.https, user_config, (req, res) => handler(req, res));

const alias = user_config.resolve && user_config.resolve.alias;

// don't warn on overriding defaults
const [modified_user_config] = deep_merge(default_config, user_config);

/** @type {[any, string[]]} */
const [merged_config, conflicts] = deep_merge(user_config, {
const [merged_config, conflicts] = deep_merge(modified_user_config, {
configFile: false,
root: this.cwd,
resolve: {
Expand Down