Security defaults
What the packages do without being asked, and the few settings that change it.
Defaults
Section titled “Defaults”- JWT verification requires an issuer, an audience and an algorithm allow-list, and refuses to start without them. The key source is fixed in configuration and never taken from the token.
- Routes and prefix middleware match the same normalised path, so percent-encoding a character cannot route around a guard.
- Route parameters that would decode to a
/, a.or..segment, a backslash or a NUL are answered404, so/files/..%2Fsecretcannot reach a parameter used as a key. - Body readers stop at a byte limit (1 MiB unless you set one) and reject invalid UTF-8.
- Cookies are
HttpOnly,SecureandSameSite=Laxunless you say otherwise, and the__Host-and__Secure-prefix rules are enforced. cors()has no default origin and refuses*together with credentials.- The logger redacts any field whose name contains
authorization,cookie,token,password,secretor a similar word, at any depth, and the access log omits the query string. Records are bounded in size and safe against cyclic data. - With
errorHandler(), error responses never include the message or headers of an error the application did not create, apart fromAllow,Retry-AfterandWWW-Authenticate. - Settings are checked when a middleware, verifier or codec is created, so a bad one stops start-up. A callback that throws, or rejects, does not change the response.
- A callback that decides access (authentication, rate limiting, CORS) fails closed: when it throws, the request is refused, or the permission is withheld.
requestId()ignores caller-supplied IDs unlesstrustInboundis set.
Settings to check before production
Section titled “Settings to check before production”- Rate limits without a binding.
rateLimit()skips limiting when itslimiterfunction returnsundefined, which lets local runs work without the binding. Setrequired: trueto answer503instead. - Limiter outages.
onLimiterErroris'reject'by default. Keep it on limits that guard against abuse or cost; use'allow'only on limits that protect capacity. - Content Security Policy.
secureHeaders()sendsdefault-src 'none', which suits an API. A service that serves HTML passes its owncontent-security-policy. - Sessions.
createSessionCodec()keeps sessions in an encrypted cookie, so one cannot be revoked before it expires. Pair it with a store where revocation matters. - Access tokens. Set
typ: 'at+jwt'on the verifier when the issuer marks access tokens that way, so an ID token from the same issuer cannot stand in for one.