Note N3 · Markasium
SINGLE SESSION AND REFRESH
Single-use refresh tokens and a cookie per panel: Redis GETDEL, one session, cookie tossing
- Sheet
- MARKASIUM
- Topic
- Spring Boot · Redis · Cookie security
- Source
- security/SessionBindingService.java
- Date
- 2026-11-12
- Reading
- 3 min
Short answer: read the refresh token from Redis with GETDEL: the value is deleted the moment it is read, so a second request with the same token at the same time finds
nothing. Keep one active session marker per user; a new login invalidates the old session's tokens. In a system where several panels share a domain, read each panel's own
cookie, and reject the request if more than one cookie with the same name arrives.
01Atomic rotation
A refresh token is replaced every time it is used; the old one can't be used again. If "read, check, delete" are three steps, two requests arriving at the same time with the
same token can both find it valid. Redis GETDEL makes those three steps one command:
// GETDEL: refresh is single-use; a second concurrent request finds nothing.
String userId = redis.opsForValue().getAndDelete(refreshOwnerKey(refreshHash));
String meta = redis.opsForValue().getAndDelete(refreshMetaKey(refreshHash));
Redis holds the refresh token's hash, not the token; even if a Redis dump leaks, sessions can't be stolen.
02The context a refresh carries
Each refresh record carries its owner, the platform it was issued for (web or mobile), and whether the session was opened with a second factor. So:
- A refresh issued on the web can't be used to get new tokens on mobile endpoints.
- An admin session not opened with 2FA can't be refreshed with admin privileges.
- During refresh the client's fingerprint (mostly the User-Agent) is compared with the recorded one. On mobile networks the IP changes often, so the IP alone isn't decisive.
03One active session
One active session marker is kept per user. A new login replaces it; the old device's access and refresh tokens are rejected by the backend. On every request the filter
chain compares the token's session id (sid) with the active marker. When an account is deleted, all its session records are deleted too; since the filters don't
look at the database, this step is essential.
04Five panels, five cookies
The customer site, restaurant panel, courier app, admin panel and founder panel use the same API. Each carries its own access cookie (acc,
acc_partner, acc_courier, acc_admin, acc_founder). Which cookie is read is decided by the request path, the
X-App-Id header or, for SSE connections that can't send headers, ?type=:
// Admin endpoints accept only the admin panel's cookie:
// another site's session or an XSS can't reach them.
if (uri.startsWith("/api/v1/admin") || CookieFactory.isAdminApp(appId) || "admin".equals(streamType)) {
return findCookie(cookies, CookieFactory.ADMIN_ACCESS_NAME);
}
An XSS on the customer site goes to admin endpoints with the customer cookie, even if the browser also holds an admin cookie, and is rejected. The path is read from the
decoded URL; encoded letters (such as %61dmin) can't sidestep the rule.
05Two sources, two cookies: both rejected
if (fromHeader != null && fromCookie != null)
throw invalidRequest("Birden fazla access token kaynağı kabul edilmez");
if (++matching > 1) throw invalidRequest("Birden fazla access cookie kabul edilmez");
If both an Authorization header and a cookie arrive, which one counts is ambiguous; the request is rejected. Two cookies with the same name are rejected too:
a second cookie forced in from a subdomain or another path (cookie tossing) is a known way to slip a user into the attacker's session.
→More notes from this project
—End of notewritten by MUHAMMEDPYZ