Does Ktor preserve session cookies across major version upgrades?
0 reputation · 06 Oct 2025, 16:06 UTC
0 reputation · 06 Oct 2025, 16:06 UTC
The goal is to determine whether session state created under an earlier Ktor major release remains valid after the application is upgraded to a newer major release, without requiring users to obtain new cookies.
Ktor's default SessionProvider is cookie-based, but its serialization format and configuration can change between major releases. Available release notes mention interceptor deprecations without clarifying whether existing session cookies are rejected, ignored, or safely deserialized after an upgrade. This leaves the compatibility of legacy session state unresolved.
Assume the upgrade path moves between supported Ktor major versions and that the application continues to use the default cookie-based SessionProvider unless explicitly replaced.
Does Ktor guarantee backward compatibility of session cookie serialization across major versions? Which SessionProvider setting controls legacy cookie deserialization after an upgrade? What happens to existing session cookies when the default serialization format changes?
35275 reputation · 06 Oct 2025, 21:24 UTC
No. Ktor does not guarantee backward compatibility of session cookie serialization across major versions. If the default SessionSerializer format changes during an upgrade, existing cookies are rejected during deserialization and the user receives a new, empty session.
The likely explanation is that the default cookie provider relies on a SessionSerializer—typically backed by Kotlinx.Serialization—whose wire format can change when Ktor upgrades its internal encoding or the serialization library version. Release notes for major upgrades often highlight API redesigns without explicitly documenting cookie-format stability, so the absence of a compatibility statement should be treated as a breaking change rather than a guarantee of continuity.
No built-in setting automatically enables legacy cookie deserialization. The extension point is the serializer property in the session configuration DSL. To preserve sessions across an upgrade, supply a custom SessionSerializer that attempts the old format first, falls back to the new format, or embeds a version marker in the cookie payload and branches on it.
ktor-server-sessions or the newer multiplatform session module) and the old/new major versions.cookieSession<MySession> { serializer = ... }.Which exact artifact and major version pair are you upgrading between? The risk differs between the legacy ktor-server-sessions artifact and newer multiplatform splits, and between specific major releases.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.