Skip to content

Commit c44ddbc

Browse files
chore: deprecate csrf.checkOrigin in favour of csrf.trustedOrigins: ['*'] (#14281)
* chore: deprecate in favour of * add note to docs * Update packages/kit/src/core/config/options.js Co-authored-by: Tee Ming <[email protected]> --------- Co-authored-by: Tee Ming <[email protected]>
1 parent bed918b commit c44ddbc

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

.changeset/eleven-papayas-share.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+
chore: make config deprecation warnings more visible

.changeset/weak-clouds-tell.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+
chore: deprecate `csrf.checkOrigin` in favour of `csrf.trustedOrigins: ['*']`

packages/kit/src/core/config/options.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import process from 'node:process';
2+
import colors from 'kleur';
23

34
/** @typedef {import('./types.js').Validator} Validator */
45

@@ -108,7 +109,11 @@ const options = object(
108109
}),
109110

110111
csrf: object({
111-
checkOrigin: boolean(true),
112+
checkOrigin: deprecate(
113+
boolean(true),
114+
(keypath) =>
115+
`\`${keypath}\` has been deprecated in favour of \`csrf.trustedOrigins\`. It will be removed in a future version`
116+
),
112117
trustedOrigins: string_array([])
113118
}),
114119

@@ -323,7 +328,7 @@ function deprecate(
323328
) {
324329
return (input, keypath) => {
325330
if (input !== undefined) {
326-
console.warn(get_message(keypath));
331+
console.warn(colors.bold().yellow(get_message(keypath)));
327332
}
328333

329334
return fn(input, keypath);

packages/kit/src/core/sync/write_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { set_private_env, set_public_env } from '${runtime_directory}/shared-ser
3737
export const options = {
3838
app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
3939
csp: ${s(config.kit.csp)},
40-
csrf_check_origin: ${s(config.kit.csrf.checkOrigin)},
40+
csrf_check_origin: ${s(config.kit.csrf.checkOrigin && !config.kit.csrf.trustedOrigins.includes('*'))},
4141
csrf_trusted_origins: ${s(config.kit.csrf.trustedOrigins)},
4242
embedded: ${config.kit.embedded},
4343
env_public_prefix: '${config.kit.env.publicPrefix}',

packages/kit/src/exports/public.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,17 @@ export interface KitConfig {
426426
*
427427
* To allow people to make `POST`, `PUT`, `PATCH`, or `DELETE` requests with a `Content-Type` of `application/x-www-form-urlencoded`, `multipart/form-data`, or `text/plain` to your app from other origins, you will need to disable this option. Be careful!
428428
* @default true
429+
* @deprecated Use `trustedOrigins: ['*']` instead
429430
*/
430431
checkOrigin?: boolean;
431432
/**
432-
* An array of origins that are allowed to make cross-origin form submissions to your app, even when `checkOrigin` is `true`.
433+
* An array of origins that are allowed to make cross-origin form submissions to your app.
433434
*
434435
* Each origin should be a complete origin including protocol (e.g., `https://payment-gateway.com`).
435436
* This is useful for allowing trusted third-party services like payment gateways or authentication providers to submit forms to your app.
436437
*
438+
* If the array contains `'*'`, all origins will be trusted. This is generally not recommended!
439+
*
437440
* **Warning**: Only add origins you completely trust, as this bypasses CSRF protection for those origins.
438441
* @default []
439442
* @example ['https://checkout.stripe.com', 'https://accounts.google.com']

packages/kit/types/index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,17 @@ declare module '@sveltejs/kit' {
402402
*
403403
* To allow people to make `POST`, `PUT`, `PATCH`, or `DELETE` requests with a `Content-Type` of `application/x-www-form-urlencoded`, `multipart/form-data`, or `text/plain` to your app from other origins, you will need to disable this option. Be careful!
404404
* @default true
405+
* @deprecated Use `trustedOrigins: ['*']` instead
405406
*/
406407
checkOrigin?: boolean;
407408
/**
408-
* An array of origins that are allowed to make cross-origin form submissions to your app, even when `checkOrigin` is `true`.
409+
* An array of origins that are allowed to make cross-origin form submissions to your app.
409410
*
410411
* Each origin should be a complete origin including protocol (e.g., `https://payment-gateway.com`).
411412
* This is useful for allowing trusted third-party services like payment gateways or authentication providers to submit forms to your app.
412413
*
414+
* If the array contains `'*'`, all origins will be trusted. This is generally not recommended!
415+
*
413416
* **Warning**: Only add origins you completely trust, as this bypasses CSRF protection for those origins.
414417
* @default []
415418
* @example ['https://checkout.stripe.com', 'https://accounts.google.com']

0 commit comments

Comments
 (0)