Skip to content

Security defaults

What the packages do without being asked, and the few settings that change it.

  • 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 answered 404, so /files/..%2Fsecret cannot 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, Secure and SameSite=Lax unless 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, secret or 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 from Allow, Retry-After and WWW-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 unless trustInbound is set.
  • Rate limits without a binding. rateLimit() skips limiting when its limiter function returns undefined, which lets local runs work without the binding. Set required: true to answer 503 instead.
  • Limiter outages. onLimiterError is '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() sends default-src 'none', which suits an API. A service that serves HTML passes its own content-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.

See Releases and security.