Back
Open Source

Fastify session rolling: exclude login and health paths without breaking saves

Fastify session #366 added an object form for rolling: { excluded: ["/session"] }. Excluded paths do not reset cookie expiration, while changed sessions still save.

JB
Josué Barros
••2 min read

Rolling sessions reset the cookie expiration on every response. That is usually what you want for an active user, but not for every route. A login check, a health probe or an asset request can keep a session alive without representing user activity.

This is one of the pull requests behind Six merged PRs in 72 hours. The series looks at the failure, the fix and the review evidence, one merge at a time.

The change: +61 / -3 across 5 files. PR 366.

The bug

The plugin had a boolean rolling option: all paths or none. There was no way to say “roll on normal requests, but not on this endpoint.” Users had to choose between drifting expirations and giving up rolling entirely.

The feature adds an object form: { excluded: ["/session"] }. A request to an excluded path does not reset the cookie expiration. A session that changed still saves, so the exclusion applies to the rolling refresh, not to persistence.

Why it mattered

Cookie lifetime is a security and UX trade-off. Rolling on a health check can keep a stale session alive; disabling rolling globally can log active users out. A per-path exclusion gives the application the control it needs without a custom plugin.

The fix

Accept an object form for rolling with an excluded path list. Keep the boolean form working unchanged. When a request is excluded, skip the expiration refresh; if the session data changed, persist the change.

The evidence

The PR uses a cookie.maxAge and tests two paths: /session is excluded and sends no set-cookie, while /check does. Unit tests keep 100% coverage and the type test passes. The test covers both the exclusion and the save path.

What I would repeat

When a boolean configuration grows a third case, turn it into a small object, not a second boolean. Preserve the old shape for compatibility. Test the two behaviors separately: “do not refresh” and “still save changes” are different contracts.

Sources

If this was useful, connect with me on LinkedIn; I write about the bugs behind merged pull requests and the evidence that gets them accepted.

FAQ

What does Fastify session rolling excluded do?
It lets specific paths skip the rolling cookie expiration refresh while still saving session changes.
Is boolean rolling still supported?
Yes. The object form is additive; boolean rolling keeps the old behavior.
How is it configured?
rolling: { excluded: ["/session"] } with a cookie.maxAge. Requests to /session do not send set-cookie; other paths do.
#fastify#session#cookies#nodejs#open-source

Join the Newsletter

Subscribe to get my latest content by email.

We won't send you spam. Unsubscribe at any time.