# Security

> What the kit protects by default, what Void already does, what you must still do, and where to change it.

*Canonical: https://makerkit.dev/docs/void-cloudflare/security/overview*

---

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](./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](./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](./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](../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](./csrf) |

## 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](../storage/overview)). 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](../configuration/environment-variables#security)) | 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

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](./content-security-policy#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](./headers)
2. [Content Security Policy](./content-security-policy)
3. [CSRF Protection](./csrf)
4. [Coding Agents](./coding-agents)

---

**Next:** [Security Headers →](./headers)
