You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OAuth2AuthorizationRequest not removed from session #7327
When #6215 was fixed only the adding of new OAuth2AuthorizationRequests was fixed, not the removal of those. With a distributed session store we observed an increase in session size for users having long running sessions.
A dump of the keys of the session attributes revealed a huge HashMap of OAuth2AuthorizationRequest. This is due to org.springframework.security.oauth2.client.web.server.WebSessionOAuth2ServerAuthorizationRequestRepository#removeAuthorizationRequest only removing the OAuth2AuthorizationRequest from the HashMap and not updating the session attributes leaving no clue to the session repository that the session was amended.
The expected behaviour would be that the stateToAuthzRequestHashMap should not grow without limit and OAuth2AuthorizationRequest should be removed after it was used to create a new session.
changed the title [-]Followup for #6215: Leaking authorization requests on distibuted sessions[/-][+]OAuth2AuthorizationRequest not removed from session[/+]on Aug 30, 2019
Thanks for the report @AndreasKl. You are right, WebSessionOAuth2ServerAuthorizationRequestRepository.removeAuthorizationRequest() does not update the sessions attributes with the updated Map of the removal of OAuth2AuthorizationRequest.
Would you be interested in submitting a PR for this fix?
Do you think it is of any value, if I also provide a PR with an optional facility that allows to limit the amount of OAuth2AuthorizationRequests for a single session. This could be an additional session attribute backed by a size limited LinkedHashMap containing the state values as keys and an empty object as value (this would have the benefit that existing sessions can be de-serialized).
Something like:
voidlimitSizeOfAuthorizationRequest(
OAuth2AuthorizationRequestoAuth2AuthorizationRequest, WebSessionwebSession) {
requireNonNull(oAuth2AuthorizationRequest, "oAuth2AuthorizationRequest must not be null");
requireNonNull(webSession, "webSession must not be null");
removeOldAuthorizationRequest(
storeMostRecentAuthorizationRequests(oAuth2AuthorizationRequest, webSession), webSession);
}
privateMap<String, String> storeMostRecentAuthorizationRequests(
OAuth2AuthorizationRequestoAuth2AuthorizationRequest, WebSessionwebSession) {
SizeLimitedHashMap<String, String> workingSet =
webSession.getAttribute(DEFAULT_AUTHORIZATION_REQUEST_LIMIT_ATTR_NAME);
if (workingSet == null) {
workingSet = newSizeLimitedHashMap<>(limit);
}
workingSet.put(oAuth2AuthorizationRequest.getState(), SOME_VALUE);
if (LOG.isDebugEnabled()) {
LOG.debug("The current active auth request states are: {}", workingSet.keySet());
}
webSession.getAttributes().put(DEFAULT_AUTHORIZATION_REQUEST_LIMIT_ATTR_NAME, workingSet);
returnworkingSet;
}
privatevoidremoveOldAuthorizationRequest(
Map<String, String> workingSet, WebSessionwebSession) {
Map<String, OAuth2AuthorizationRequest> oAuth2AuthorizationRequests =
webSession.getAttribute(DEFAULT_AUTHORIZATION_REQUEST_ATTR_NAME);
if (oAuth2AuthorizationRequests == null) {
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug(
"Auth request state keys before cleanup: {}", oAuth2AuthorizationRequests.keySet());
}
oAuth2AuthorizationRequests.keySet().retainAll(workingSet.keySet());
if (LOG.isDebugEnabled()) {
LOG.debug("Auth request state keys after cleanup: {}", oAuth2AuthorizationRequests.keySet());
}
webSession
.getAttributes()
.put(DEFAULT_AUTHORIZATION_REQUEST_ATTR_NAME, oAuth2AuthorizationRequests);
}
Do you think it is of any value, if I also provide a PR with an optional facility that allows to limit the amount of OAuth2AuthorizationRequests for a single session
The existing issue #5145 tracks this enhancement. We would need this enhancement implemented on both the Servlet and Reactive side. It would be great if you can provide a PR?
Activity
[-]Followup for #6215: Leaking authorization requests on distibuted sessions[/-][+]OAuth2AuthorizationRequest not removed from session[/+]jgrandja commentedon Aug 30, 2019
Thanks for the report @AndreasKl. You are right,
WebSessionOAuth2ServerAuthorizationRequestRepository.removeAuthorizationRequest()does not update the sessions attributes with the updatedMapof the removal ofOAuth2AuthorizationRequest.Would you be interested in submitting a PR for this fix?
AndreasKl commentedon Aug 30, 2019
@jgrandja Would be happy to provide the PR.
Do you think it is of any value, if I also provide a PR with an optional facility that allows to limit the amount of
OAuth2AuthorizationRequests for a single session. This could be an additional session attribute backed by a size limitedLinkedHashMapcontaining thestatevalues as keys and an empty object as value (this would have the benefit that existing sessions can be de-serialized).Something like:
jgrandja commentedon Sep 3, 2019
@AndreasKl
The existing issue #5145 tracks this enhancement. We would need this enhancement implemented on both the Servlet and Reactive side. It would be great if you can provide a PR?
AndreasKl commentedon Sep 3, 2019
@jgrandja Thanks for the hint, wasn't aware there is already an open issue.
Remove OAuth2AuthorizationRequest when a distributed session is used