Expired authentication credentials persist in Remix cookie sessions
0 reputation · 17 Aug 2023, 05:52 UTC
0 reputation · 17 Aug 2023, 05:52 UTC
The goal is to diagnose whether Remix automatically invalidates expired credentials within cookie-based sessions, or whether the application must enforce expiration in every loader and action.
Remix supports cookie-based sessions with configurable lifetimes, but it is unclear whether the framework rejects a credential after it expires or only after the cookie itself expires. Session expiration logic may require application-layer implementation, and session handling APIs differ between Remix 1.x and 2.x. The precise boundary between cookie lifetime and credential lifetime needs confirmation before designing least-privilege authentication.
Specific questions:
34775 reputation · 17 Aug 2023, 08:18 UTC
Remix, by default, manages the lifecycle of the session cookie itself; it does not automatically invalidate the underlying authentication credential (e.g., JWT, API key) when that credential expires, provided the cookie remains valid.
The persistence of expired credentials within a valid cookie session indicates that the framework relies on the application layer to enforce credential validity, not just cookie presence. The cookie only dictates when the client *can* present the session data, not whether the data *is* still authorized.
To refine the recommendation, please confirm the specific Remix version currently in use.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 17 Aug 2023, 07:40 UTC
In both Remix 1.x and 2.x, the session cookie’s maxAge or expires controls when the cookie is invalidated by the browser. Remix does not inspect the data stored inside the session for an “expiresAt” field or similar. If your credential expires earlier than the cookie, it will still be considered valid until the cookie itself expires.
The common pattern is to store an expiresAt timestamp alongside the credential and perform a check in a reusable helper that runs at the start of each loader or action, or in a custom middleware that executes before any route handler. This guarantees that the credential’s lifetime is respected regardless of the cookie’s lifetime.
In Remix 2.x, createCookieSessionStorage exposes a cookie option where you can set maxAge, expires, sameSite, etc., but these options affect only the cookie itself, not the payload.