@sveltejs/kit 1.0.0-next.461 → 1.0.0-next.462
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
|
@@ -125,6 +125,10 @@ const options = object(
|
|
|
125
125
|
reportOnly: directives
|
|
126
126
|
}),
|
|
127
127
|
|
|
128
|
+
csrf: object({
|
|
129
|
+
checkOrigin: boolean(true)
|
|
130
|
+
}),
|
|
131
|
+
|
|
128
132
|
// TODO: remove this for the 1.0 release
|
|
129
133
|
endpointExtensions: error(
|
|
130
134
|
(keypath) => `${keypath} has been renamed to config.kit.moduleExtensions`
|
|
@@ -54,6 +54,9 @@ export class Server {
|
|
|
54
54
|
constructor(manifest) {
|
|
55
55
|
this.options = {
|
|
56
56
|
csp: ${s(config.kit.csp)},
|
|
57
|
+
csrf: {
|
|
58
|
+
check_origin: ${s(config.kit.csrf.checkOrigin)},
|
|
59
|
+
},
|
|
57
60
|
dev: false,
|
|
58
61
|
get_stack: error => String(error), // for security
|
|
59
62
|
handle_error: (error, event) => {
|
|
@@ -377,6 +377,9 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
|
377
377
|
request,
|
|
378
378
|
{
|
|
379
379
|
csp: svelte_config.kit.csp,
|
|
380
|
+
csrf: {
|
|
381
|
+
check_origin: svelte_config.kit.csrf.checkOrigin
|
|
382
|
+
},
|
|
380
383
|
dev: true,
|
|
381
384
|
get_stack: (error) => fix_stack_trace(error),
|
|
382
385
|
handle_error: (error, event) => {
|
|
@@ -18,6 +18,21 @@ const default_transform = ({ html }) => html;
|
|
|
18
18
|
export async function respond(request, options, state) {
|
|
19
19
|
let url = new URL(request.url);
|
|
20
20
|
|
|
21
|
+
if (options.csrf.check_origin) {
|
|
22
|
+
const type = request.headers.get('content-type')?.split(';')[0];
|
|
23
|
+
|
|
24
|
+
const forbidden =
|
|
25
|
+
request.method === 'POST' &&
|
|
26
|
+
request.headers.get('origin') !== url.origin &&
|
|
27
|
+
(type === 'application/x-www-form-urlencoded' || type === 'multipart/form-data');
|
|
28
|
+
|
|
29
|
+
if (forbidden) {
|
|
30
|
+
return new Response(`Cross-site ${request.method} form submissions are forbidden`, {
|
|
31
|
+
status: 403
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
21
36
|
const { parameter, allowed } = options.method_override;
|
|
22
37
|
const method_override = url.searchParams.get(parameter)?.toUpperCase();
|
|
23
38
|
|
package/types/index.d.ts
CHANGED
package/types/internal.d.ts
CHANGED
|
@@ -290,6 +290,9 @@ export type SSRNodeLoader = () => Promise<SSRNode>;
|
|
|
290
290
|
|
|
291
291
|
export interface SSROptions {
|
|
292
292
|
csp: ValidatedConfig['kit']['csp'];
|
|
293
|
+
csrf: {
|
|
294
|
+
check_origin: boolean;
|
|
295
|
+
};
|
|
293
296
|
dev: boolean;
|
|
294
297
|
get_stack: (error: Error) => string | undefined;
|
|
295
298
|
handle_error(error: Error & { frame?: string }, event: RequestEvent): void;
|