@sveltejs/kit 2.49.4 → 2.49.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "2.49.4",
3
+ "version": "2.49.5",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -23,7 +23,7 @@
23
23
  "@types/cookie": "^0.6.0",
24
24
  "acorn": "^8.14.1",
25
25
  "cookie": "^0.6.0",
26
- "devalue": "^5.3.2",
26
+ "devalue": "^5.6.2",
27
27
  "esm-env": "^1.2.2",
28
28
  "kleur": "^4.1.5",
29
29
  "magic-string": "^0.30.5",
@@ -41,7 +41,7 @@
41
41
  "@types/set-cookie-parser": "^2.4.7",
42
42
  "dts-buddy": "^0.6.2",
43
43
  "rollup": "^4.14.2",
44
- "svelte": "^5.42.1",
44
+ "svelte": "^5.46.4",
45
45
  "svelte-preprocess": "^6.0.0",
46
46
  "typescript": "^5.3.3",
47
47
  "vite": "^6.3.5",
@@ -122,17 +122,6 @@ export function filter_fonts(assets) {
122
122
  return assets.filter((asset) => /\.(woff2?|ttf|otf)$/.test(asset));
123
123
  }
124
124
 
125
- const method_names = new Set(['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'OPTIONS']);
126
-
127
- // If we'd written this in TypeScript, it could be easy...
128
- /**
129
- * @param {string} str
130
- * @returns {str is import('types').HttpMethod}
131
- */
132
- export function is_http_method(str) {
133
- return method_names.has(str);
134
- }
135
-
136
125
  /**
137
126
  * @param {import('types').ValidatedKitConfig} config
138
127
  * @returns {string}
@@ -803,6 +803,8 @@ async function kit({ svelte_config }) {
803
803
  /** @type {import('vite').UserConfig} */
804
804
  let new_config;
805
805
 
806
+ const kit_paths_base = kit.paths.base || '/';
807
+
806
808
  if (is_build) {
807
809
  const ssr = /** @type {boolean} */ (config.build?.ssr);
808
810
  const prefix = `${kit.appDir}/immutable`;
@@ -884,7 +886,7 @@ async function kit({ svelte_config }) {
884
886
  // That's larger and takes longer to run and also causes an HTML diff between SSR and client
885
887
  // causing us to do a more expensive hydration check.
886
888
  const client_base =
887
- kit.paths.relative !== false || kit.paths.assets ? './' : kit.paths.base || '/';
889
+ kit.paths.relative !== false || kit.paths.assets ? './' : kit_paths_base;
888
890
 
889
891
  const inline = !ssr && svelte_config.kit.output.bundleStrategy === 'inline';
890
892
  const split = ssr || svelte_config.kit.output.bundleStrategy === 'split';
@@ -943,7 +945,7 @@ async function kit({ svelte_config }) {
943
945
  } else {
944
946
  new_config = {
945
947
  appType: 'custom',
946
- base: kit.paths.base,
948
+ base: kit_paths_base,
947
949
  build: {
948
950
  rollupOptions: {
949
951
  // Vite dependency crawler needs an explicit JS entry point
@@ -5,6 +5,7 @@
5
5
  import { DEV } from 'esm-env';
6
6
  import * as devalue from 'devalue';
7
7
  import { text_decoder, text_encoder } from './utils.js';
8
+ import { SvelteKitError } from '@sveltejs/kit/internal';
8
9
 
9
10
  /**
10
11
  * Sets a value in a nested object using a path string, mutating the original object
@@ -64,7 +65,7 @@ export function convert_formdata(data) {
64
65
 
65
66
  export const BINARY_FORM_CONTENT_TYPE = 'application/x-sveltekit-formdata';
66
67
  const BINARY_FORM_VERSION = 0;
67
-
68
+ const HEADER_BYTES = 1 + 4 + 2;
68
69
  /**
69
70
  * The binary format is as follows:
70
71
  * - 1 byte: Format version
@@ -144,7 +145,11 @@ export async function deserialize_binary_form(request) {
144
145
  return { data: convert_formdata(form_data), meta: {}, form_data };
145
146
  }
146
147
  if (!request.body) {
147
- throw new Error('Could not deserialize binary form: no body');
148
+ throw deserialize_error('no body');
149
+ }
150
+ const content_length = parseInt(request.headers.get('content-length') ?? '');
151
+ if (Number.isNaN(content_length)) {
152
+ throw deserialize_error('invalid Content-Length header');
148
153
  }
149
154
 
150
155
  const reader = request.body.getReader();
@@ -156,7 +161,7 @@ export async function deserialize_binary_form(request) {
156
161
  * @param {number} index
157
162
  * @returns {Promise<Uint8Array<ArrayBuffer> | undefined>}
158
163
  */
159
- async function get_chunk(index) {
164
+ function get_chunk(index) {
160
165
  if (index in chunks) return chunks[index];
161
166
 
162
167
  let i = chunks.length;
@@ -195,8 +200,7 @@ export async function deserialize_binary_form(request) {
195
200
  return start_chunk.subarray(offset - chunk_start, offset + length - chunk_start);
196
201
  }
197
202
  // Otherwise, copy the data into a new buffer
198
- const buffer = new Uint8Array(length);
199
- buffer.set(start_chunk.subarray(offset - chunk_start));
203
+ const chunks = [start_chunk.subarray(offset - chunk_start)];
200
204
  let cursor = start_chunk.byteLength - offset + chunk_start;
201
205
  while (cursor < length) {
202
206
  chunk_index++;
@@ -205,6 +209,12 @@ export async function deserialize_binary_form(request) {
205
209
  if (chunk.byteLength > length - cursor) {
206
210
  chunk = chunk.subarray(0, length - cursor);
207
211
  }
212
+ chunks.push(chunk);
213
+ cursor += chunk.byteLength;
214
+ }
215
+ const buffer = new Uint8Array(length);
216
+ cursor = 0;
217
+ for (const chunk of chunks) {
208
218
  buffer.set(chunk, cursor);
209
219
  cursor += chunk.byteLength;
210
220
  }
@@ -212,21 +222,28 @@ export async function deserialize_binary_form(request) {
212
222
  return buffer;
213
223
  }
214
224
 
215
- const header = await get_buffer(0, 1 + 4 + 2);
216
- if (!header) throw new Error('Could not deserialize binary form: too short');
225
+ const header = await get_buffer(0, HEADER_BYTES);
226
+ if (!header) throw deserialize_error('too short');
217
227
 
218
228
  if (header[0] !== BINARY_FORM_VERSION) {
219
- throw new Error(
220
- `Could not deserialize binary form: got version ${header[0]}, expected version ${BINARY_FORM_VERSION}`
221
- );
229
+ throw deserialize_error(`got version ${header[0]}, expected version ${BINARY_FORM_VERSION}`);
222
230
  }
223
231
  const header_view = new DataView(header.buffer, header.byteOffset, header.byteLength);
224
232
  const data_length = header_view.getUint32(1, true);
233
+
234
+ if (HEADER_BYTES + data_length > content_length) {
235
+ throw deserialize_error('data overflow');
236
+ }
237
+
225
238
  const file_offsets_length = header_view.getUint16(5, true);
226
239
 
240
+ if (HEADER_BYTES + data_length + file_offsets_length > content_length) {
241
+ throw deserialize_error('file offset table overflow');
242
+ }
243
+
227
244
  // Read the form data
228
- const data_buffer = await get_buffer(1 + 4 + 2, data_length);
229
- if (!data_buffer) throw new Error('Could not deserialize binary form: data too short');
245
+ const data_buffer = await get_buffer(HEADER_BYTES, data_length);
246
+ if (!data_buffer) throw deserialize_error('data too short');
230
247
 
231
248
  /** @type {Array<number>} */
232
249
  let file_offsets;
@@ -234,18 +251,20 @@ export async function deserialize_binary_form(request) {
234
251
  let files_start_offset;
235
252
  if (file_offsets_length > 0) {
236
253
  // Read the file offset table
237
- const file_offsets_buffer = await get_buffer(1 + 4 + 2 + data_length, file_offsets_length);
238
- if (!file_offsets_buffer)
239
- throw new Error('Could not deserialize binary form: file offset table too short');
254
+ const file_offsets_buffer = await get_buffer(HEADER_BYTES + data_length, file_offsets_length);
255
+ if (!file_offsets_buffer) throw deserialize_error('file offset table too short');
240
256
 
241
257
  file_offsets = /** @type {Array<number>} */ (
242
258
  JSON.parse(text_decoder.decode(file_offsets_buffer))
243
259
  );
244
- files_start_offset = 1 + 4 + 2 + data_length + file_offsets_length;
260
+ files_start_offset = HEADER_BYTES + data_length + file_offsets_length;
245
261
  }
246
262
 
247
263
  const [data, meta] = devalue.parse(text_decoder.decode(data_buffer), {
248
264
  File: ([name, type, size, last_modified, index]) => {
265
+ if (files_start_offset + file_offsets[index] + size > content_length) {
266
+ throw deserialize_error('file data overflow');
267
+ }
249
268
  return new Proxy(
250
269
  new LazyFile(
251
270
  name,
@@ -276,6 +295,12 @@ export async function deserialize_binary_form(request) {
276
295
 
277
296
  return { data, meta, form_data: null };
278
297
  }
298
+ /**
299
+ * @param {string} message
300
+ */
301
+ function deserialize_error(message) {
302
+ return new SvelteKitError(400, 'Bad Request', `Could not deserialize binary form: ${message}`);
303
+ }
279
304
 
280
305
  /** @implements {File} */
281
306
  class LazyFile {
@@ -380,7 +405,7 @@ class LazyFile {
380
405
  chunk_index++;
381
406
  let chunk = await this.#get_chunk(chunk_index);
382
407
  if (!chunk) {
383
- controller.error('Could not deserialize binary form: incomplete file data');
408
+ controller.error('incomplete file data');
384
409
  controller.close();
385
410
  return;
386
411
  }
@@ -294,6 +294,7 @@ async function handle_remote_form_post_internal(event, state, manifest, id) {
294
294
  const fn = /** @type {RemoteInfo & { type: 'form' }} */ (/** @type {any} */ (form).__).fn;
295
295
 
296
296
  const { data, meta, form_data } = await deserialize_binary_form(event.request);
297
+
297
298
  if (action_id && !('id' in data)) {
298
299
  data.id = JSON.parse(decodeURIComponent(action_id));
299
300
  }
@@ -247,8 +247,10 @@ export async function internal_respond(request, options, manifest, state) {
247
247
  return text('Malformed URI', { status: 400 });
248
248
  }
249
249
 
250
+ // try to serve the rerouted prerendered resource if it exists
250
251
  if (
251
- resolved_path !== url.pathname &&
252
+ // the resolved path has been decoded so it should be compared to the decoded url pathname
253
+ resolved_path !== decode_pathname(url.pathname) &&
252
254
  !state.prerendering?.fallback &&
253
255
  has_prerendered_path(manifest, resolved_path)
254
256
  ) {
@@ -259,20 +261,24 @@ export async function internal_respond(request, options, manifest, state) {
259
261
  ? add_resolution_suffix(resolved_path)
260
262
  : resolved_path;
261
263
 
262
- // `fetch` automatically decodes the body, so we need to delete the related headers to not break the response
263
- // Also see https://github.com/sveltejs/kit/issues/12197 for more info (we should fix this more generally at some point)
264
- const response = await fetch(url, request);
265
- const headers = new Headers(response.headers);
266
- if (headers.has('content-encoding')) {
267
- headers.delete('content-encoding');
268
- headers.delete('content-length');
269
- }
264
+ try {
265
+ // `fetch` automatically decodes the body, so we need to delete the related headers to not break the response
266
+ // Also see https://github.com/sveltejs/kit/issues/12197 for more info (we should fix this more generally at some point)
267
+ const response = await fetch(url, request);
268
+ const headers = new Headers(response.headers);
269
+ if (headers.has('content-encoding')) {
270
+ headers.delete('content-encoding');
271
+ headers.delete('content-length');
272
+ }
270
273
 
271
- return new Response(response.body, {
272
- headers,
273
- status: response.status,
274
- statusText: response.statusText
275
- });
274
+ return new Response(response.body, {
275
+ headers,
276
+ status: response.status,
277
+ statusText: response.statusText
278
+ });
279
+ } catch (error) {
280
+ return await handle_fatal_error(event, event_state, options, error);
281
+ }
276
282
  }
277
283
 
278
284
  /** @type {import('types').SSRRoute | null} */
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '2.49.4';
4
+ export const VERSION = '2.49.5';
package/types/index.d.ts CHANGED
@@ -2769,7 +2769,7 @@ declare module '@sveltejs/kit' {
2769
2769
  class Redirect_1 {
2770
2770
 
2771
2771
  constructor(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, location: string);
2772
- status: 301 | 302 | 303 | 307 | 308 | 300 | 304 | 305 | 306;
2772
+ status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
2773
2773
  location: string;
2774
2774
  }
2775
2775