Skip to content

clearCookie does not include configured cookie path #345

Description

@0XFF-96

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

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

  1. Configure @fastify/session with a custom cookie path:
fastify.register(fastifySession, {
  secret: 'a secret with minimum length 32 chars',
  cookie: { path: '/admin' }
})

  1. Send a request to /admin with an existing stale session cookie.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions