Skip to content

Commit de3be9a

Browse files
authored
fix: posixify internal app server path (#14049)
Noticed this while working on remote functions - this could yield false negatives on windows for resolving internal server path and for the server module guard (there's no security issue here, this would've just failed right away both at runtime and build time since the imported server code, which is only SvelteKit runtime code and not user code, is invalid in the browser)
1 parent fade97a commit de3be9a

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

.changeset/loose-tips-go.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: posixify internal app server path

packages/kit/src/exports/vite/module_ids.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { fileURLToPath } from 'node:url';
2+
import { posixify } from '../../utils/filesystem.js';
23

34
export const env_static_private = '\0virtual:env/static/private';
45
export const env_static_public = '\0virtual:env/static/public';
@@ -11,6 +12,6 @@ export const sveltekit_environment = '\0virtual:__sveltekit/environment';
1112
export const sveltekit_paths = '\0virtual:__sveltekit/paths';
1213
export const sveltekit_server = '\0virtual:__sveltekit/server';
1314

14-
export const app_server = fileURLToPath(
15-
new URL('../../runtime/app/server/index.js', import.meta.url)
15+
export const app_server = posixify(
16+
fileURLToPath(new URL('../../runtime/app/server/index.js', import.meta.url))
1617
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
import { read } from '$app/server';
3+
read;
4+
</script>

packages/kit/test/apps/dev-only/test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ Tips:
7676
- If you're not sure which module is causing this, try building your app -- it will create a more helpful error.`);
7777
});
7878

79+
test('$app/server module is not statically importable from the client', async ({ page }) => {
80+
await page.goto('/illegal-imports/server-only-modules/static-import-2', {
81+
wait_for_started: false
82+
});
83+
expect(await page.textContent('.message-body'))
84+
.toBe(`Cannot import $app/server into client-side code. This could leak sensitive information.
85+
Tips:
86+
- To resolve this error, ensure that no exports from $app/server are used, even transitively, in client-side code.
87+
- If you're only using the import as a type, change it to \`import type\`.
88+
- If you're not sure which module is causing this, try building your app -- it will create a more helpful error.`);
89+
});
90+
7991
test('server-only module is not dynamically importable from the client', async ({ page }) => {
8092
await page.goto('/illegal-imports/server-only-modules/dynamic-import', {
8193
wait_for_started: false

0 commit comments

Comments
 (0)