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
Copy file name to clipboardExpand all lines: src/routes/solid-start/guides/security.mdx
+4-2Lines changed: 4 additions & 2 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).
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
+35-8Lines changed: 35 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,39 @@ 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
+
Seroval defines the supported value types and edge cases. See the full list in the Seroval compatibility docs.
85
+
59
86
## Configuring Nitro
60
87
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.
88
+
SolidStart uses [Nitro](https://nitro.build/) to run on a number of platforms.
89
+
The `server` option exposes some Nitro options including the build and deployment presets.
63
90
An overview of all available presets is available in the [Deploy section of the Nitro documentation](https://nitro.build/deploy).
64
91
65
-
Some common ones include:
92
+
Some common ones include:
66
93
67
94
**Servers**
68
95
@@ -99,7 +126,7 @@ export default defineConfig({
99
126
100
127
#### Special note
101
128
102
-
SolidStart uses async local storage.
129
+
SolidStart uses async local storage.
103
130
Netlify, Vercel, and Deno support this out of the box but if you're using Cloudflare you will need to specify the following:
104
131
105
132
```js
@@ -117,7 +144,6 @@ export default defineConfig({
117
144
118
145
Within `wrangler.toml` you will need to enable node compatibility:
0 commit comments