Skip to content

v0.6.0

Release Date: 2026-10-25

Highlights

Security release for the session and kvs/backend/redis packages. Session IDs are validated and no longer appear in logs, violation events or errors; SiteID is enforced on every session operation; and the Redis backend requires TLS and a password for remote servers. This release contains breaking changes; see Upgrading.

Security Fixes

Session IDs validated in the kvs backend

The kvs session backend stores sessions at KeyPrefix+id and each user's session index at KeyPrefix+"user:"+userID, and took session IDs as given. Since session IDs come from client cookies, the ID user:<id> addressed a user's index: Delete removed it, so DeleteByUserID ("log out everywhere", revoke on password change) and per-user session limits no longer found that user's sessions.

The new session.ValidSessionID accepts 1 to MaxSessionIDLength (256) URL-safe characters (A-Z, a-z, 0-9, -, _, .), which covers GenerateSessionID. The kvs backend refuses other IDs: Create and Update return ErrInvalidSession, Get returns ErrNotFound, and Delete is a no-op. Get and Delete also require the stored record to be a session with the requested ID, so Delete never removes another record.

Session IDs kept out of logs and errors

ControlledStore put the full session ID into its violation log lines, into ViolationEvent.SessionID passed to violation handlers, into SessionError details and into the eviction log. Session IDs are bearer credentials, so anyone with access to logs, metrics or error reports could take over the session.

The new session.SessionRef returns a non-reversible reference: the first 8 hex characters of the SHA-256 of the ID. Violation and eviction logs record session_ref, ViolationEvent carries it in the new SessionRef field, and SessionError details use the session_ref key. ViolationEvent.SessionID is deprecated and no longer set.

SiteID enforced on Update, Delete, Touch and DeleteByUserID

ControlledStore stamped SiteID on Create and checked it on Get, but Update wrote the session as given, and Delete, Touch and DeleteByUserID passed straight through. A caller that rebuilt a session without SiteID before updating it (for example on token refresh) stored site "", after which Get reported the session as not found. These methods also acted on sessions of another site sharing the same backend, and one site's "log out everywhere" ended the user's sessions on every site.

When SiteID is configured:

Operation Behaviour for a session of another site
Update Returns ErrNotFound; otherwise stamps the configured SiteID before writing
Delete Leaves it in place and returns nil, as for a missing session
Touch Returns ErrNotFound
DeleteByUserID Deletes only this site's sessions; returns an error and deletes nothing if the store does not implement SessionLister

Each mismatch is reported as a site_mismatch violation, as Get already did. Behaviour is unchanged when SiteID is empty.

Redis: TLS and a password for remote servers

kvsredis.New accepted any redis:// URL, so a remote Redis could be used over plaintext and without authentication. Everything stored, such as session data and tokens, crossed the network unencrypted and was open to anyone who could reach the server.

New now refuses a server on a non-loopback address unless the URL uses rediss:// with certificate verification enabled and includes a password, returning an error that wraps kvsredis.ErrInsecureConnection. Loopback addresses and Unix sockets are still allowed. The new Config.AllowInsecure restores the previous behaviour for trusted networks.

Redis: escaped prefix in List

List built its SCAN MATCH pattern as KeyPrefix+prefix+"*" without escaping, so glob metacharacters in either part were interpreted. A prefix such as user:* or a? matched keys outside the requested prefix, including other namespaces sharing the Redis instance. The literal prefix now has \, *, ?, [ and ] escaped, and List drops any returned key that does not start with the full requested prefix.

Fixed

  • The kvs session backend logged nothing when its best-effort user index maintenance failed, and when Create could not read a user's index it overwrote it with only the new session, hiding the user's other sessions from DeleteByUserID. Each failure is now logged with slog.WarnContext and the user ID (never the session ID), and Create no longer writes the index when reading it fails.

Added

  • session.ValidSessionID and session.MaxSessionIDLength
  • session.SessionRef and ViolationEvent.SessionRef
  • kvsredis.Config.AllowInsecure and kvsredis.ErrInsecureConnection

Upgrading

Violation handlers, logs and metrics

ViolationEvent.SessionID is always empty. Read SessionRef instead:

// Before
metrics.Violation(event.Type, event.SessionID)

// After
metrics.Violation(event.Type, event.SessionRef)

Log queries, alerts and dashboards that match the session_id key in violation or eviction logs, or in SessionError.Details, must use session_ref. To find the entries for a session ID you hold, compute its reference:

ref := session.SessionRef(sessionID) // e.g. "3f1c9a2e"

Redis connections

A non-loopback Redis server now needs TLS with certificate verification and a password:

// Before
store, err := kvsredis.New(kvsredis.Config{
    URL: "redis://cache.example.com:6379",
})

// After
store, err := kvsredis.New(kvsredis.Config{
    URL: "rediss://app:" + password + "@cache.example.com:6380/0",
})

Remove skip_verify=true from the URL. If the network path to Redis is trusted and TLS or a password is not available, opt out explicitly:

store, err := kvsredis.New(kvsredis.Config{
    URL:           "redis://cache.internal:6379",
    AllowInsecure: true,
})

Check for the new error with errors.Is(err, kvsredis.ErrInsecureConnection). Loopback and unix:// URLs need no change.

Session IDs

Generate session IDs with session.GenerateSessionID. If you generate your own, make sure every ID passes session.ValidSessionID. Sessions already stored in the kvs backend under an ID that does not pass can no longer be read or deleted through the store; those users sign in again, and the records expire with their TTL.

Multi-site deployments

  • Set the same SiteID in every process that serves one site; a process with a different SiteID can no longer update, touch or delete that site's sessions.
  • DeleteByUserID with SiteID set needs a store that implements SessionLister. Both bundled backends (session/backend/memory and session/backend/kvs) do; a custom store must implement ListByUserID.
  • To end a user's sessions on every site, call DeleteByUserID through each site's ControlledStore, or on the underlying store directly.

Update the module

go get github.com/plexusone/[email protected]
go mod tidy

Documentation

  • KVS guide and README describe the Redis connection requirements and AllowInsecure
  • Session controls guide describes site enforcement on every operation, site-scoped DeleteByUserID and session_ref

Dependencies

  • Bump github.com/grokify/oscompat from 0.5.0 to 0.7.0
  • Bump github.com/klauspost/compress from 1.20.1 to 1.20.3
  • Bump golang.org/x/crypto from 0.57.0 to 0.58.0

Full Changelog

See CHANGELOG.md for the complete list of changes.