You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A code is executed from vite.config.ts upon opening .svelte file. For example, opening file from non-trusted svelte source may perform unwanted changed to a filesystem: e.g. rm -rf $HOME. This is a surprising behavior in a default configuration.
Reproduction
#!/bin/sh
npx sv create --template minimal --types ts --no-add-ons --no-install baz
cd baz
cat > src/routes/+page.svelte <<EOF
<script lang="ts">
</script>
<form method="POST">
</form>
<style>
</style>
EOF
cat >> vite.config.ts <<EOF
import { writeFile } from "fs";
writeFile("/tmp/gotcha.txt", "", () => {});
process.exit(1);
EOF
npm i svelte-language-server
export PATH=$(pwd)/node_modules/.bin:$PATH # so emacs can find svelteserver
emacs src/routes/+page.svelte
ls -l /tmp/gotcha.txt # <<< file has been created
Expected behaviour
No code executed from a project on file open in a default configuration. If code execution is necessary for some features, it should be explicit opt-in.
Reading svelte.config.js, thus vite.config.ts, for preprocess setup is a core part of the svelte compiler diagnostic. So I am not sure if it's possible to make it opt-in without affecting most people. This also requires the language server client to provide a way to configure this opt-in since reading a config file has the same problem.
In VSCode, there is a "workspace trust" feature that svelte-language-server supports. The first time you open a directory it'll ask if trust the workspace. If you don't trust it, the supported extension can disable specific features.
The most possible solution I can think of is that you can hook into this "trust" feature on the language server side. You can pass in isTrusted in the initialization option for the svelte language server to "untrust" the workspace.
Thanks, that is helpful! Though, it is surprising, that the default is "trusted". From security conscious point of view the default should be closed, not open.
Apparently, there is no builtin way of configuring out "trusted workspace" in emacs. Emacs does configure bunch of svelte-server setting: https://github.com/emacs-lsp/lsp-mode/blob/master/clients/lsp-svelte.el#L228 . Do you know what it the way for enabling isTrusted? I assume it is also a part of the initialization message?
Describe the bug
A code is executed from
vite.config.ts
upon opening.svelte
file. For example, opening file from non-trusted svelte source may perform unwanted changed to a filesystem: e.g.rm -rf $HOME
. This is a surprising behavior in a default configuration.Reproduction
Expected behaviour
No code executed from a project on file open in a default configuration. If code execution is necessary for some features, it should be explicit opt-in.
System Info
npm:
emacs: 30.0.93
lsp-mode: 20250116.14
Which package is the issue about?
svelte-language-server
Additional Information, eg. Screenshots
No response
The text was updated successfully, but these errors were encountered: