Spring Security 6.2 defaults to InMemoryOidcSessionRegistry causing memory leaks in distributed systems with external session storage #14558
Labels
in: oauth2
An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
type: bug
A general bug
Milestone
Describe the bug
Default configuration of
InMemoryOidcSessionRegistry
causes memory leak in cloud environments using external session storage systems such asorg.springframework.session:spring-session-data-redis
.This
default
caused JVM OOMs in our production system for multiple days until we boiled it down using heap dumps from production containers.This was introduced with spring security 6.2 or might happen if you update from spring boot starter 3.1.6 to 3.2.x while using spring session with an external storage.
To Reproduce
Excerpt from the build.gradle
Expected behavior
This might be a communication issue in the documentation of the change logs.
Setting the default to
InMemoryOidcSessionRegistry
is a breaking change for applications that are running in a cloud environment with non-sticky sessions.I would either recommend removing the default or clearly communicating this as a breaking change in the behavior of spring security.
This change requires configuration changes to stay functional.
Related Documentation
OidcSessionStrategy
.SessionAuthenticationStrategy
which is doing something else.OidcSessionRegistry
is meant here.Our mitigation
We would mitigate this issue by providing a custom
OidcSessionRegistry
implementation that does not store the session information in memory.Spring Data Redis is already configured to store the session information in Redis.
We also implemented a custom back-channel logout endpoint to remove the session information from the Redis store by wiping the http session.
In this particular case, we would use the
NoopSpringDataOidcSessionsStrategy
to avoid the memory leak until further support for external data storage is added.Sample
Creating a sample costs a lot of time and is not feasible for us at the moment.
We are happy to provide a sample if it is required.
Related issues
The text was updated successfully, but these errors were encountered: