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
server function payloads, data transfer, csp, security, performance
5
+
tags:
6
+
- serialization
7
+
- server-functions
8
+
- csp
9
+
- security
10
+
- performance
11
+
version: "1.0"
12
+
description: >-
13
+
Understand how SolidStart serializes server function payloads, supported
14
+
types, and CSP tradeoffs.
15
+
---
16
+
17
+
SolidStart serializes server function arguments and return values so they can travel between server and client. It uses Seroval under the hood and streams payloads to keep responses responsive.
18
+
19
+
## Configuration
20
+
21
+
Configure serialization in your `app.config.ts` with `defineConfig`:
Seroval supports additional value types. The compatibility list is broader than what SolidStart enables by default, so treat it as a superset. See the [Seroval compatibility docs](https://github.com/lxsmnsyc/seroval/blob/main/docs/COMPATIBILITY.md).
69
+
70
+
## Limits and exclusions
71
+
72
+
-`RegExp` is disabled by default.
73
+
- JSON mode enforces a maximum serialization depth of 64. If you exceed this, flatten the structure or return a simpler payload.
74
+
75
+
## Related guidance
76
+
77
+
- Configure modes and defaults in [`defineConfig`](/solid-start/reference/config/define-config#serialization).
78
+
- CSP implications and nonce examples live in the [Security guide](/solid-start/guides/security#content-security-policy-csp).
Copy file name to clipboardExpand all lines: src/routes/solid-start/guides/security.mdx
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ tags:
11
11
- csp
12
12
- middleware
13
13
- protection
14
-
version: '1.0'
14
+
version: "1.0"
15
15
description: >-
16
16
Secure your SolidStart apps against XSS, CSRF attacks. Configure CSP headers,
17
17
CORS policies, and implement security best practices.
@@ -38,12 +38,14 @@ It is highly recommended to read the [Cross Site Scripting Prevention Cheat Shee
38
38
39
39
To configure the `Content-Security-Policy` HTTP header, a [middleware](/solid-start/advanced/middleware) can be used.
40
40
41
+
If you enforce a strict CSP, configure SolidStart to use JSON serialization mode to avoid `unsafe-eval` requirements. See [defineConfig serialization](/solid-start/reference/config/define-config#serialization). Note that `unsafe-eval` is only required for `serialization.mode: "js"`.
42
+
41
43
### With nonce (recommended)
42
44
43
45
If you want to use a [strict CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#strict_csp) with nonces:
44
46
45
47
1. Create a middleware that configures the CSP header.
46
-
It must then be registered using the [`onRequest`](/solid-start/advanced/middleware#onrequest) event.
48
+
It must then be registered using the [`onRequest`](/solid-start/advanced/middleware#onrequest) event.
47
49
2. Create a nonce using a cryptographic random value generator, such as the [`randomBytes`](https://nodejs.org/api/crypto.html#cryptorandombytessize-callback) function from the `crypto` module.
48
50
3. Store the nonce in the [`locals`](/solid-start/advanced/middleware#locals) object.
49
51
4. Configure SolidStart to use the nonce in your [`entry-server.tsx`](/solid-start/reference/entrypoints/entry-server) file.
Copy file name to clipboardExpand all lines: src/routes/solid-start/reference/config/define-config.mdx
+44-8Lines changed: 44 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ tags:
10
10
- deployment
11
11
- build
12
12
- plugins
13
-
version: '1.0'
13
+
version: "1.0"
14
14
description: >-
15
15
Configure SolidStart apps with defineConfig. Set up Vite plugins, Nitro
16
16
presets, and deployment targets for any platform.
@@ -35,11 +35,12 @@ export default defineConfig({
35
35
});
36
36
```
37
37
38
-
The `vite` option can also be a function that can be customized for each Vinxi router.
38
+
The `vite` option can also be a function that can be customized for each Vinxi router.
39
39
40
40
In SolidStart, 3 routers are used:
41
+
41
42
-`server` - server-side routing
42
-
-`client` - for the client-side routing
43
+
-`client` - for the client-side routing
43
44
-`server-function` - server functions.
44
45
45
46
```tsx
@@ -56,13 +57,48 @@ export default defineConfig({
56
57
});
57
58
```
58
59
60
+
## Serialization
61
+
62
+
SolidStart serializes server function payloads so they can move between server and client. You can configure the serializer mode to balance performance, payload size, and Content Security Policy (CSP) constraints.
-`json`: Uses `JSON.parse` on the client. This is the safest option for strict CSP because it avoids `eval`. Payloads can be slightly larger.
77
+
-`js`: Uses Seroval's JS serializer for smaller payloads and better performance, but it relies on `eval` during client-side deserialization and requires `unsafe-eval` in CSP.
78
+
79
+
### Defaults
80
+
81
+
- SolidStart v1 defaults to `js` for backwards compatibility.
82
+
- SolidStart v2 defaults to `json` for CSP compatibility.
83
+
84
+
### Supported types (default)
85
+
86
+
SolidStart enables Seroval plus a default set of web platform plugins. These plugins add support for:
Seroval supports additional value types. The compatibility list is broader than what SolidStart enables by default, so treat it as a superset. See the full list in the [Seroval compatibility docs](https://github.com/lxsmnsyc/seroval/blob/main/docs/COMPATIBILITY.md).
94
+
59
95
## Configuring Nitro
60
96
61
-
SolidStart uses [Nitro](https://nitro.build/) to run on a number of platforms.
62
-
The `server` option exposes some Nitro options including the build and deployment presets.
97
+
SolidStart uses [Nitro](https://nitro.build/) to run on a number of platforms.
98
+
The `server` option exposes some Nitro options including the build and deployment presets.
63
99
An overview of all available presets is available in the [Deploy section of the Nitro documentation](https://nitro.build/deploy).
64
100
65
-
Some common ones include:
101
+
Some common ones include:
66
102
67
103
**Servers**
68
104
@@ -99,7 +135,7 @@ export default defineConfig({
99
135
100
136
#### Special note
101
137
102
-
SolidStart uses async local storage.
138
+
SolidStart uses async local storage.
103
139
Netlify, Vercel, and Deno support this out of the box but if you're using Cloudflare you will need to specify the following:
104
140
105
141
```js
@@ -117,7 +153,6 @@ export default defineConfig({
117
153
118
154
Within `wrangler.toml` you will need to enable node compatibility:
0 commit comments