Security Headers and Rate Limiting in Nuxt
This starter kit uses the nuxt-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:
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:
export default defineNuxtConfig({
security: {
rateLimiter: false,
},
})
NUXT_PRIVATE_REDIS_URL is set.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.
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.
Umami
Track page views and events in your Nuxt app with the nuxt-umami module and a self-hosted Umami instance, or replace it with another analytics provider.
Testing
Unit tests with Vitest plus API and browser tests with Playwright against a real production server and PostgreSQL. Only Polar and email are mocked.