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

[security] upgrade to Vite 2.6.12, specify allow list, and print warning #2691

Merged
merged 8 commits into from
Oct 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-frogs-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[security] upgrade to Vite 2.6.12, specify allow list, and print warning
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
"cheap-watch": "^1.0.4",
"sade": "^1.7.4",
"vite": "^2.6.11"
"vite": "^2.6.12"
},
"devDependencies": {
"@rollup/plugin-replace": "^3.0.0",
Expand Down
17 changes: 15 additions & 2 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { existsSync } from 'fs';
import sade from 'sade';
import colors from 'kleur';
import { relative } from 'path';
import * as ports from 'port-authority';
import { load_config } from './core/config/index.js';
import { networkInterfaces, release } from 'os';
Expand Down Expand Up @@ -111,7 +112,14 @@ prog
https = https || !!config.kit.vite().server?.https;
open = open || !!config.kit.vite().server?.open;

welcome({ port: address_info.port, host: address_info.address, https, open });
welcome({
port: address_info.port,
host: address_info.address,
https,
open,
allow: watcher.allowed_directories(),
cwd: watcher.cwd
});
} catch (error) {
handle_error(error);
}
Expand Down Expand Up @@ -221,9 +229,11 @@ async function check_port(port) {
* host: string;
* https: boolean;
* port: number;
* allow?: string[];
* cwd?: string;
* }} param0
*/
function welcome({ port, host, https, open }) {
function welcome({ port, host, https, open, allow, cwd }) {
if (open) launch(port, https);

console.log(colors.bold().cyan(`\n SvelteKit v${'__VERSION__'}\n`));
Expand All @@ -244,6 +254,9 @@ function welcome({ port, host, https, open }) {

if (exposed) {
console.log(` ${colors.gray('network:')} ${protocol}//${colors.bold(`${details.address}:${port}`)}`);
if (allow?.length && cwd) {
console.log(`\n ${colors.yellow('Note that all files in the following directories will be accessible to anyone on your network: ' + allow.map(a => relative(cwd, a)).join(', '))}`);
}
} else {
console.log(` ${colors.gray('network: not exposed')}`);
}
Expand Down
17 changes: 16 additions & 1 deletion packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ class Watcher extends EventEmitter {
});
}

allowed_directories() {
return [
...new Set([
this.config.kit.files.assets,
this.config.kit.files.lib,
this.config.kit.files.routes,
path.resolve(this.cwd, 'src'),
path.resolve(this.cwd, '.svelte-kit'),
path.resolve(this.cwd, 'node_modules'),
path.resolve(vite.searchForWorkspaceRoot(this.cwd), 'node_modules')
])
];
}

async init_server() {
if (!this.manifest) throw new Error('Must call init() before init_server()');

Expand All @@ -101,7 +115,8 @@ class Watcher extends EventEmitter {
const default_config = {
server: {
fs: {
strict: true
strict: true,
allow: this.allowed_directories()
},
strictPort: true
}
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.