Skip to content

Harden sessionCategory switches against future categories #19

Description

@aaronbrethorst

Follow-up from PR #12 (refactor: replace magic session numbers with sessionType), which introduced the sessionCategory enum in handlers/common/session_store.go. The refactor is a strict improvement; these are non-blocking hardening items for when a fourth session category is eventually added.

1. Non-exhaustive switch handling (most meaningful)

Four switches over sessionType disagree on how they treat an unrecognized category:

  • validateSessiondefault: return false (fail-closed, good)
  • setSession — no default; unknown category stores the entry with no timestamps
  • estimateMemoryUsage — no default; unknown category contributes 0 (cosmetic)
  • ExpireSession — no default; unknown category leaves timeout == 0, so the session is not expired despite the helper's name

None are reachable today (the public API only ever supplies valid constants), but adding a fourth category would let several switches silently do the wrong thing. Options: add the exhaustive golangci-lint analyzer, or add explicit default: arms to the three switches that lack one (panicking or choosing a safe value in ExpireSession).

2. Document the iota zero-value assumption

disambiguation == 0 means a zero-valued SessionEntry is implicitly disambiguation. This is safe only because sessions are in-memory and always explicitly constructed (never deserialized). A one-line comment on the const block would protect a future maintainer who adds persistence.

3. Minor: String() fallback + dead code

  • String() is currently unused; it's reasonable forward-looking logging/test infrastructure, just noting it.
  • Consider fmt.Sprintf("sessionCategory(%d)", int(s)) instead of "unknown" so an unexpected value is diagnosable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions