---
title: "Security Headers and Rate Limiting in Nuxt"
description: "Security headers and CSP with Nuxt Security, its default rate limiter and what to check behind a proxy, protected admin APIs and file upload validation."
canonical_url: "https://nuxtstarterkit.com/docs/security"
---

> Index of every page on this site: [llms.txt](https://nuxtstarterkit.com/llms.txt)

This starter kit uses the [nuxt-security](https://nuxt.com/modules/security) Nuxt module to enhance the security of your application. This module provides a set of security headers and best practices to help protect your application from common vulnerabilities and attacks.

The module is registered in the `core` layer. Its configuration is in `apps/web/layers/core/nuxt.config.ts`, where you can enable or disable specific security features and customize their settings:

```ts [apps/web/layers/core/nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['nuxt-security'],
  security: {
    headers: {
      contentSecurityPolicy: {
        // img-src, script-src, …
      },
      crossOriginEmbedderPolicy: false,
    },
    nonce: true,
  },
})
```

## Rate Limiting

The kit doesn't change Nuxt Security's rate limiter, so its default applies: **150 requests per route and client IP within 5 minutes**. Requests above that get a `429`. The counters live in memory, so they reset when the server restarts and aren't shared between several instances.

The limiter takes the client IP from the `X-Forwarded-For` header. Behind a proxy or CDN (e.g. Cloudflare and Traefik), check which IP actually reaches your app before you launch. If all requests arrive with the proxy's IP, all users share one limit. Configure `rateLimiter.ipHeader` for your setup, or turn the limiter off:

```ts [apps/web/layers/core/nuxt.config.ts]
export default defineNuxtConfig({
  security: {
    rateLimiter: false,
  },
})
```

<note>

The kit has no stricter limits for the contact form or the waitlist signup. better-auth rate-limits its own endpoints per client IP in production, with the same proxy caveat. File uploads have a separate limit per user (100 uploads per minute), which only runs when `NUXT_PRIVATE_REDIS_URL` is set.

</note>

## Admin API

Every admin API handler starts with `await requireAdmin(event)`. It returns `401` without a session and `403` without the admin role, in addition to the admin route middleware. A unit test fails when a handler under `server/api/dashboard/admin/` doesn't call it. See [Authentication](https://nuxtstarterkit.com/docs/authentication#require-the-admin-role).

## File Uploads

The upload API detects the file type from the file content and ignores the MIME type and file name the client sends. Only PNG, JPEG, GIF, WebP, AVIF and PDF can be uploaded, so an HTML or SVG file disguised as an image is rejected with `415`. See [Images](https://nuxtstarterkit.com/docs/images#allowed-file-types-and-size).

## Sitemap

See the full [sitemap](https://nuxtstarterkit.com/sitemap.md) for all pages.
