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

ProtectionAgainstWherePage
Security headers (nosniff, X-Frame-Options, Referrer-Policy, Permissions-Policy, COOP, HSTS)MIME sniffing, clickjacking, referrer leaks, unused browser APIs, http downgradesapps/web/middleware/03.security.tsHeaders
Content Security Policy, per-response nonceInjected inline handlers, javascript: URLs, eval, scripts from unknown originsapps/web/middleware/03.security.ts + apps/web/config/security.config.tsContent Security Policy
Rules, redacted tools and blocked remote tools for coding agentsAn agent leaking a secret or changing Stripe, Cloudflare or production dataAGENTS.md, .claude/settings.json, .mcp.jsonCoding Agents
Rate limits on public routes that are not sign-inFloods of cheap requests (health checks, error reports, your uploads)apps/web/config/rate-limits.config.tsOperations: Rate Limits
Origin check on /api/* writesOther sites posting to your API with the user's cookies (CSRF)apps/web/middleware/04.api-origin.ts + apps/web/config/security.config.tsCSRF

What Void Already Does

  • Page actions (Form, useForm, action exports) reject cross-origin browser submissions with 403.
  • Env values are validated at startup and by void env check; diagnostics redact the value.
  • router.visit() refuses javascript: 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 crossSiteApiPaths only if it needs it.
  • Never mutate data in a GET handler. 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 with nosniff (Storage). Never add a second upload route or let the client choose a key.

Configuration

WhatWhereOwner
Third-party origins per CSP directiveapps/web/config/security.config.ts → cspYou
Webhook paths that accept cross-site writesapps/web/config/security.config.ts → crossSiteApiPathsYou
CSP on, report-only or offCSP_MODE env variable (reference)You, per environment
Header values, base policy, origin checkapps/web/middleware/03.security.ts, 04.api-origin.tsThe kit (override in your own middleware or handler instead)

Production Checklist

  1. Every subdomain of your production domain serves https (HSTS includeSubDomains forces it for two years).
  2. CSP_MODE is unset or enforce in production (void secret list shows whether it's set).
  3. Each third-party service you load (analytics, chat, payments) has its origins in security.config.ts, and the browser console shows no CSP violations under vp preview.
  4. Each webhook handler verifies the provider's signature; any path in crossSiteApiPaths is a webhook.
  5. 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.
  6. If you embed the app in an iframe anywhere, you've changed X-Frame-Options and frame-ancestors deliberately.

Topics

  1. Security Headers
  2. Content Security Policy
  3. CSRF Protection
  4. Coding Agents

Next: Security Headers →