Drumee
Engineering

Session Management Security: How Drumee Handles Sign-In and Sessions

Session management security is how an application proves, on every request, that the caller is still the person who signed in, and how it ends that proof the moment it should no longer hold. Drumee uses opaque, server-side sessions: a random token...

Drumee session design: a __Host- cookie carries a random token, the server stores only its SHA-256 hash, and revoking a device ends its session and realtime…

Drumee session design: a __Host- cookie carries a random token, the server stores only its SHA-256 hash, and revoking a device ends its session and realtime…

Session management security is how an application proves, on every request, that the caller is still the person who signed in, and how it ends that proof the moment it should no longer hold. Drumee uses opaque, server-side sessions: a random token in a hardened cookie, only its hash in the database, and revocation that takes effect at once.

This post walks through the design on Drumee Cloud, the hosted service at app.drumee.com: the five directory collections behind sign-in, the cookie flags, expiry and revocation, one-time codes, CSRF and CORS, and the sign-in history. Facts come from the Request Pipeline and Directory Schema docs. For tenant isolation and encryption at rest, read our data protection post; this one stays on identity.

The short answer

Drumee signs a person in by issuing a random 256-bit token in an HttpOnly, Secure, SameSite=Lax cookie with the __Host- prefix, and stores only the token's SHA-256 hash. Every request looks the session up on the server. Sessions expire after 30 days idle or 90 days in any case, and signing out, removing a device or changing a password ends them immediately.

Around that core sit Argon2id password checks with per-account and per-address limits, an optional or mandatory second factor, one-time codes bound to a single action, CSRF protection without tokens, and a sign-in log with a result for every attempt.

Architecture diagram: browser cookie through TLS edge and middleware (CORS, session, rate limit, CSRF) to the sessions and users collections, with Redis sign-in challenges and a login_events log

From cookie to user: how a Drumee request is authenticated.

Five collections behind sign-in

Identity lives in Drumee's global database, the directory, because a person exists before and across any organization. Five collections carry sign-in:

Table: Drumee identity collections users, sessions, email_tokens, otp_codes and login_events, with the secret each stores as a hash and how each expires

Every secret is stored as a hash or keyed digest; short-lived records expire through TTL indexes.

  • users: the account. Email in lower case, an Argon2id password_hash (absent for accounts that only sign in with Google or Apple), the mfa object, linked oauth providers, a status (active, blocked, archived, pending_deletion, registration_incomplete) and a credentials_version.
  • sessions: one document per signed-in device, holding token_hash, device (name, OS, browser, user agent), the ip at sign-in, last_used_at, expires_at, revoked_at with a reason, and reauth_at.
  • email_tokens: links sent by email, of kind verify, reset, email_change or email_undo, stored as the SHA-256 of the token in the link.
  • otp_codes: six-digit one-time codes, each bound to one user and one action, with an attempt counter.
  • login_events: the sign-in history, with address, client and a result for every attempt.

Two conventions run through all of them: IDs "identify; they are not secrets", while random tokens are generated separately and stored only as hashes; and short-lived documents carry expires_at and are removed by a TTL index.

Opaque, server-side sessions: the design choice

Many web apps use self-contained tokens such as JSON Web Tokens: the token carries its own claims and a signature, so the server can validate it without a lookup. Drumee deliberately does not. Its sessions are "opaque and stored on the server — not self-contained tokens."

The trade-off is simple to state:

  • Cost: every request performs a session lookup.
  • Benefit: the server, not the token, decides whether a session is valid. Revocation is a write to one document, and it takes effect on the next request rather than when a token's lifetime runs out.

The lookup checks three things: the session is not revoked, it is not expired, and the account is active. A blocked account therefore stops working everywhere at once, without waiting for any token to age out.

Because sessions live in MongoDB rather than in a server's memory, any server can serve any request. The modular monolith post explains why that stateless design lets Drumee add or replace servers freely.

The session cookie, flag by flag

At sign-in the server generates a random 256-bit token. The browser gets the token; the database gets only its SHA-256 hash, so a copy of the database contains no usable session. The cookie carries four protections, each closing a different door (MDN: Set-Cookie):

Set-Cookie: __Host-<name>=<random 256-bit token>; HttpOnly; Secure; SameSite=Lax; Path=/
  • HttpOnly: page scripts cannot read the cookie, so an injected script cannot copy the token out.
  • Secure: the cookie is only sent over HTTPS.
  • SameSite=Lax: the browser does not attach it to most cross-site requests, a second layer against CSRF.
  • __Host- prefix: the cookie is bound to the exact host, which prevents a sibling subdomain from planting one.

The cookie name and Path above are illustrative; the docs specify the flags and prefix. Mobile and API clients may send the token in an Authorization: Bearer header instead. The token is never accepted from a URL, so it cannot leak through browser history, logs or a referrer.

Lifetime: idle and absolute expiry

A Drumee session has two clocks:

  • Idle expiry: 30 days without use. expires_at is extended on use, so an active device stays signed in.
  • Absolute expiry: 90 days in any case. Even a device used every day signs in again after 90 days.

The idle limit cleans up forgotten devices; the absolute limit bounds how long any single token can live, however it is used. That pairing is the pattern the OWASP Session Management Cheat Sheet recommends. A TTL index on expires_at removes expired sessions from the collection automatically.

Revocation: what ends a session

Table: what ends a Drumee session: sign out, removing a device, password change, 30 days idle, 90 days absolute and an inactive account

Explicit actions end sessions at once; the two expiry clocks end the rest.

Because the session is a server record, ending it is immediate. Signing out, removing a device or changing a password "ends the affected sessions at once and disconnects their realtime connections." The revoked_at and revoked_reason fields record when and why.

As the Drumee FAQ puts it, this is what makes a lost device easy to handle. Users see this in Account → Sessions, which lists every device signed in to the account; Revoke signs a device out immediately (Component definition). The device name, operating system and browser shown there come from the session's device field.

The realtime channel follows the same rule. The WebSocket handshake is authenticated with the same session as the API and accepted only from the application's own origins, and a revoked session closes the connection. Revoking a device therefore also stops it receiving new messages or file events, not just making new requests.

Changing credentials invalidates half-finished sign-ins

users.credentials_version is incremented when the password or the second factor changes, and it "invalidates sign-in steps started before the change." Consider an attacker who has a stolen password and has passed the first step, waiting at the two-factor prompt. If the owner changes the password at that moment, the attacker's pending challenge is dead, not just their future attempts.

The sign-in flow

Steps: Drumee sign-in checks the password with Argon2id under rate limits, returns a short-lived challenge if two-factor is on, verifies a code, then opens a session

The password alone opens a session only when no second factor is enabled or required.

1. email + password  -> Argon2id verify, limits per account and per address,
                        same timing whether or not the email exists
2. 2FA on/required?  -> short-lived challenge (Redis), no session yet
3. code              -> authenticator | emailed code | recovery code
4. success           -> random 256-bit token: cookie to browser, hash to sessions
5. every attempt     -> login_events row with its result

A few details matter:

  • Constant timing. Sign-in takes the same time whether or not the email exists, so response time does not reveal which addresses have accounts.
  • Two limits. Attempts are limited per account and per address. The account limit slows guessing against one person; the address limit slows one source spraying many accounts.
  • Trusted client address. The reverse proxy sets the client address, and the server accepts it only from proxies it is configured to trust, so a client cannot forge its address to dodge rate limits.
  • No session before the second factor. With two-factor authentication enabled by the user, or required by the organization for admins or for everyone, the password step returns a short-lived challenge kept in Redis. The session opens only after a valid authenticator code, emailed code or recovery code. Authenticator seeds are encrypted and recovery codes are keyed digests, removed once used.
  • Social sign-in, same session. Google and Apple sign-in use the standard authorization-code flow, bound to the browser that started it, and end in the same kind of session.

The organizations and admin post covers how Security admins require two-step sign-in across an organization.

One-time codes and email links

Drumee uses two kinds of short-lived proof besides the password.

One-time codes (otp_codes) are six digits. Each is stored as a keyed digest (HMAC-SHA256) "bound to the user and the action", and "a code is valid for one action only." The documented actions include sign-in, email change and data export. A code issued to confirm an email change cannot be replayed to export the account, and a database copy reveals no usable code. An attempts counter tracks wrong guesses.

Email links (email_tokens) carry a random token whose SHA-256 is stored, for verifying an address, resetting a password, changing an email or undoing an email change. Reset links count tries, the submissions that reached the check.

What about passwordless login codes? The schema lists sign-in among the actions a one-time code can authorize, and the pipeline accepts an emailed code as a second factor. Accounts created with Google or Apple can have no password at all (oauth_only). The docs do not state whether a password account can sign in with an emailed code alone.

Re-authentication for sensitive actions

A valid session is not always enough. The reauth_at field records the last re-authentication, "required for sensitive actions". The docs name several:

  • Data export. Downloading an archive of everything requires a recent re-authentication.
  • Account deletion. Requires the password or a one-time code.
  • Organization transfer. Requires a one-time code sent by email (RBAC System).

Someone at an unlocked, signed-in browser cannot walk away with the whole account.

Login history: login_events

Every sign-in attempt is written to login_events with the user, email, address, client and one of seven results:

  • ok: signed in
  • bad_password: wrong password
  • not_found: no account for that address
  • mfa_pending: password accepted, second factor awaited
  • locked, blocked and superseded: refused or replaced attempts, recorded under their own codes

An index on (user_id, created_at) makes one person's history cheap to read, and attempts on unknown addresses expire after 30 days, so the log of probes against non-existent accounts does not grow forever. An mfa_pending with no ok after it points to a password that is known but stopped at the second factor.

CSRF and CORS without tokens

Cookies are sent automatically, which is why cross-site request forgery exists. Drumee prevents it without CSRF tokens (OWASP CSRF Prevention):

  1. Every state-changing request must carry a custom header.
  2. A browser will not let another site send a custom header without a CORS preflight.
  3. The preflight is refused for any origin not on the allow-list of the application's own origins.
  4. SameSite=Lax on the cookie is a second layer.

The middleware chain applies these in a fixed order, so authentication, budgets and CSRF are never skipped by one route:

 6 CORS         allow-list of the application's own origins
 7 App tokens   installed apps, checked against their scopes
 8 Session      cookie or bearer token -> user
 9 Rate limit   per user, or per address when anonymous
10 CSRF         state-changing requests must come from the app
11 Require      private routes refuse an unauthenticated caller (401)

Authentication happens in middleware; authorization does not. The service checks the caller's role next to the code that performs the action, as our RBAC post explains.

Why this design

Three principles explain most of the choices above:

  • Assume the database leaks. Sessions, email tokens and codes are stored only as hashes or keyed digests, and passwords as Argon2id, so a copy of the database contains no password, no usable session and no usable code. The Data Storage & Encryption docs give the full table.
  • The server decides. A session is valid because a server record says so, not because a token claims it. That is what makes "remove a device" instant.
  • Bind proof to its purpose. A code works for one action, a cookie for one host, a challenge only until the credentials change.

FAQ

What is session management security?

It is the set of controls that create, validate and end a user's signed-in state: how the token is generated and stored, which cookie flags protect it, how long it lives, and how it is revoked. In Drumee, sessions are opaque random tokens whose hashes are checked on the server on every request.

What makes Drumee's session cookies secure?

The cookie is HttpOnly, Secure, SameSite=Lax and uses the __Host- prefix, which binds it to the exact host. It carries a random 256-bit token, the database stores only its SHA-256 hash, and the token is never accepted from a URL.

How long does a Drumee session last?

A session expires after 30 days without use and after 90 days in any case. Signing out, removing the device or changing your password ends it earlier, immediately.

Does Drumee support passwordless login codes?

Drumee uses six-digit one-time codes bound to a single action, including sign-in, and accepts an emailed code as a second factor. Accounts created with Google or Apple can sign in without a password. Whether a password account can sign in with an emailed code alone is not stated in the documentation.

Does Drumee keep a login history?

Yes. Every sign-in attempt is recorded in a login_events collection with the address, client and a result such as ok, bad_password, locked or mfa_pending. Attempts on unknown addresses expire after 30 days.

How do I sign out a lost device?

Open Account, then Sessions, and revoke the device. Sessions are stored on the server, so this ends that session immediately and closes any open realtime connection.

Conclusion

Drumee's session design trades one lookup per request for control: a hashed random token in a hardened cookie, two expiry clocks, codes bound to one action, and revocation that is instant because the server holds the truth. Read how roles decide what a signed-in person may do in the RBAC post.

Try Drumee with your team: your first month is $1. Start your team for $1

Keep reading