Security
What the kit protects by default, what Void already does, what you must still do, and where to change it.
The kit ships with browser-level protections switched on: security headers on every response, an enforced Content Security Policy in production, and CSRF protection for API routes. You configure them in one file and one env variable.
What the Kit Protects
| Protection | Against | Where | Page |
|---|---|---|---|
Security headers (nosniff, X-Frame-Options, Referrer-Policy, Permissions-Policy, COOP, HSTS) | MIME sniffing, clickjacking, referrer leaks, unused browser APIs, http downgrades | apps/web/middleware/03.security.ts | Headers |
| Content Security Policy, per-response nonce | Injected inline handlers, javascript: URLs, eval, scripts from unknown origins | apps/web/middleware/03.security.ts + apps/web/config/security.config.ts | Content Security Policy |
| Rules, redacted tools and blocked remote tools for coding agents | An agent leaking a secret or changing Stripe, Cloudflare or production data | AGENTS.md, .claude/settings.json, .mcp.json | Coding Agents |
| Rate limits on public routes that are not sign-in | Floods of cheap requests (health checks, error reports, your uploads) | apps/web/config/rate-limits.config.ts | Operations: Rate Limits |
Origin check on /api/* writes | Other sites posting to your API with the user's cookies (CSRF) | apps/web/middleware/04.api-origin.ts + apps/web/config/security.config.ts | CSRF |
What Void Already Does
- Page actions (
Form,useForm,actionexports) reject cross-origin browser submissions with403. - Env values are validated at startup and by
void env check; diagnostics redact the value. router.visit()refusesjavascript:URLs.
What You Must Still Do
The defaults stop the browser being used against your users. They don't know who may do what:
- Authorize in every action and handler. Middleware, layouts and the origin check only gate navigation or other sites; a signed-in user can call any endpoint directly.
- Verify webhook signatures before acting on a webhook, and list its path in
crossSiteApiPathsonly if it needs it. - Never mutate data in a
GEThandler. The origin check doesn't cover reads. - Sanitize untrusted HTML before
dangerouslySetInnerHTML: scripts in server-rendered HTML get the nonce. - Take uploads through
@kit/storage: it picks the R2 key on the server, checks the file's real type and serves it withnosniff(Storage). Never add a second upload route or let the client choose a key.
Configuration
| What | Where | Owner |
|---|---|---|
| Third-party origins per CSP directive | apps/web/config/security.config.ts → csp | You |
| Webhook paths that accept cross-site writes | apps/web/config/security.config.ts → crossSiteApiPaths | You |
| CSP on, report-only or off | CSP_MODE env variable (reference) | You, per environment |
| Header values, base policy, origin check | apps/web/middleware/03.security.ts, 04.api-origin.ts | The kit (override in your own middleware or handler instead) |
Production Checklist
- Every subdomain of your production domain serves https (HSTS
includeSubDomainsforces it for two years). CSP_MODEis unset orenforcein production (void secret listshows whether it's set).- Each third-party service you load (analytics, chat, payments) has its origins in
security.config.ts, and the browser console shows no CSP violations undervp preview. - Each webhook handler verifies the provider's signature; any path in
crossSiteApiPathsis a webhook. - Pages in
pages/(marketing)/render only repo content or a sanitized content source (no query params, headers, user input or unsanitized HTML): their cookieless responses are cached and carry no CSP (Cached Marketing Pages). Pages that show user data stay outside that folder. - If you embed the app in an iframe anywhere, you've changed
X-Frame-Optionsandframe-ancestorsdeliberately.
Topics
Next: Security Headers →