[Bug]: OIDC mobile login sessions are never cleaned up (openIdAuthSession Map grows without limit)

Author: zoujunhui1Created Sep 25, 2026Updated Sep 25, 2026
Labelsbug

What happened?

The OIDC auth strategy keeps mobile login sessions in an in-memory Map (openIdAuthSession in server/auth/OidcAuthStrategy.js). An entry is added when a login starts (before the redirect to the identity provider), but it is only removed when the user comes back and finishes the mobile callback. The Map has no expiry (TTL) and no size limit, so any login that does not finish leaves an entry in memory forever. The Map only grows; restarting the server is the only way to clear it.

Code path:

  • Line 18 — this.openIdAuthSession = new Map() (a plain Map, no TTL, no cap)
  • Line 324 — this.openIdAuthSession.set(state, {...}) in getAuthorizationUrl, runs before the user logs in. On the mobile flow the state key comes from the client (line 307).
  • Line 485 / 497 — handleMobileRedirect has the only delete (line 497), and only on the success path. If the returned state does not match, it returns early and deletes nothing.

What did you expect to happen?

Entries for login flows that never finish should be cleaned up so the Map cannot grow without limit. For example: give each entry a short TTL (a login flow should finish within minutes) and drop expired entries on write; optionally cap the number of entries.

Steps to reproduce the issue

  1. Enable OIDC and use the mobile login flow (with a redirect_uri in the whitelist).
  2. Start a login (the authorize endpoint). An entry is added to openIdAuthSession (line 324).
  3. Do not finish the login — close the browser at the identity provider, or let the callback come back with a different state.
  4. The entry stays in the Map. handleMobileRedirect (line 497) is the only place that deletes it, and it is not reached.

Audiobookshelf version

v2.36.0

How are you running audiobookshelf?

Built from source

What OS is your Audiobookshelf server hosted from?

macOS

If the issue is being seen in the UI, what browsers are you seeing the problem on?

None

Logs

bash

Additional Notes

No response