Prerequisites
Fastify version
5.x
Plugin version
11.1.1
Node.js version
22.22.2
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
26.5.2
Description
When cookie.path is configured, stale session cookies may not be cleared correctly.
Cookie deletion must target the same cookie identity that was originally set. Browsers identify cookies by name, domain, and path. Currently, the cleanup path passes domain to reply.clearCookie(), but does not pass the configured path.
So, a session cookie set with a custom path such as /admin may be cleared with the default path /, leaving the original /admin cookie in place.
Miniual Reproduction
- Configure
@fastify/session with a custom cookie path:
fastify.register(fastifySession, {
secret: 'a secret with minimum length 32 chars',
cookie: { path: '/admin' }
})
- Send a request to /admin with an existing stale session cookie.
- Observe the Set-Cookie header used to clear the cookie.
Expected Behavior
The clearing response should include the configured path:
Set-Cookie: sessionId=; Max-Age=0; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT
Actual Behavior
The clearing response uses the default path instead of the configured path:
Set-Cookie: sessionId=; Max-Age=0; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT
This does not clear the original cookie if it was set with Path=/admin.
Prerequisites
Fastify version
5.x
Plugin version
11.1.1
Node.js version
22.22.2
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
26.5.2
Description
When
cookie.pathis configured, stale session cookies may not be cleared correctly.Cookie deletion must target the same cookie identity that was originally set. Browsers identify cookies by
name,domain, andpath. Currently, the cleanup path passesdomaintoreply.clearCookie(), but does not pass the configuredpath.So, a session cookie set with a custom path such as
/adminmay be cleared with the default path/, leaving the original/admincookie in place.Miniual Reproduction
@fastify/sessionwith a custom cookie path:Expected Behavior
Set-Cookie: sessionId=; Max-Age=0; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMTActual Behavior
Set-Cookie: sessionId=; Max-Age=0; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMTThis does not clear the original cookie if it was set with Path=/admin.