Open rikukissa opened 2 months ago
What if we handled the logout via a route in the login app? The main app could redirect the user there, and if offline, poll a logout
(invalidateToken?) endpoint in gateway until it responds and adds the token to Redis invalidations. Since the login app is offline-capable and cached, offline users could still be redirected.
There's a risk the token never invalidates, but we can mitigate this with shorter token expiration times.
This also enables a configurable LOGOUT_URL
(or LOGIN_URL + '/logout'
found from window.config), making third-party logout integration with core easier.
@naftis I don't think login app can access the token as it's in register.
Open questions
/logout
route to gateway which is fully a backend route that redirects to login? Would this compromise logging out offline?Security assessment details
Technical Overview
Potential Impact if Exploited
Recommendations
Investigate and improve
There are two options why the logout mechanism did not invalidate JWT. First is simple misconfiguration. Second one is harder to confirm since missing awaits introduces time complexity to software. Are we relying on some things happening in sequence that do not necessarily do so?
CHECK_INVALID_TOKEN
env variable was set to falseImprovements:
CHECK_INVALID_TOKEN
is explicitly set on countryconfig. On others, we trust that countryconfig extends coredocker-compose.yml
.CHECK_INVALID_TOKEN
Current logout implementation is optimistic. Within
removeToken
we call async function,authApi.invalidateToken(token)
, which is never awaited.Depending on the scenario, token could have been removed from localStorage and user redirected to login without ensuring the invalidation took place. There are multiple places where login action is handled. Some of them may implicitly rely on not awaiting for the invalidation, so just adding the missing await might cause some other failure.
// Page.tsx
checkAuth
// ProtectedRoute.tsxrefreshToken
// apolloClientcreateClient
// packages/client/src/utils/authUtils.ts
// packages/client/src/utils/authUtils.ts
Improvements:
REDIRECT_TO_AUTHENTICATION
actions through service. Check whether they are called unnecessarily. Do we run through the same steps multiple times? Can the application go to invalid state?