Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
secureCookies()
Make every cookie your app sets Secure (HTTPS-only) by default, alongside HttpOnly and SameSite.
Use case
A single cookie set without the Secure flag can be sent over plain HTTP and captured on the network. Rather
than remembering the flag on every res.cookie call, this middleware makes secure the default, so a stray
cookie cannot leak.
How it works
It overrides res.cookie so each cookie gets Secure unless you explicitly opt out, plus HttpOnly (not
readable by JavaScript) and SameSite=Lax (not sent on cross-site navigations). Then it calls next(). Your
handlers keep calling res.cookie exactly as before; the flags are added for you.
Configuration
No options. Register it in production so every cookie is hardened by default.
Example
Notes
In local development over plain HTTP a
Securecookie will not be stored by the browser. Gate this middleware on production (or skip it in dev) so your local session cookies still work, while production always gets the hardened defaults.
Next: ipFilter.