Skip to content

Session change doesn't remove old session #1519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
finke-ba opened this issue Oct 2, 2019 · 9 comments
Closed

Session change doesn't remove old session #1519

finke-ba opened this issue Oct 2, 2019 · 9 comments
Assignees
Labels
for: external-project For an external project and not something we can fix

Comments

@finke-ba
Copy link

finke-ba commented Oct 2, 2019

Hello @vpavic.

SpringSessionWebSessionStore in method changeSessionId() only change session id, but doesn't remove old one.

public Mono<Void> changeSessionId() {
	return Mono.defer(() -> {
		this.session
				.changeSessionId();
		return save();
	});
}

But in default implementation of SessionStore - InMemoryWebSessionStore it delete current one first and create new after that:

public Mono<Void> changeSessionId() {
	String currentId = this.id.get();
	InMemoryWebSessionStore.this.sessions.remove(currentId);
	String newId = String.valueOf(idGenerator.generateId());
	this.id.set(newId);
	InMemoryWebSessionStore.this.sessions.put(this.getId(), this);
	return Mono.empty();
}

Was it implemented without deleting old session by purpose and what is the correct way of removing old session in this case?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 2, 2019
@vpavic
Copy link
Contributor

vpavic commented Oct 3, 2019

Hi @finke-ba, thanks for reaching out.

Conceptually, Spring WebFlux's InMemoryWebSessionStore and Spring Session's SpringSessionWebSessionStore are quite different, because in case of default WebFlux implementation everything's in-memory and there's no concept of session repository like in Spring Session's implementation. When you actually do WebSession#changeSessionId on a WebSession that's backed by Spring Session's ReactiveSessionRepository it's actually repository's responsibility to take care of the removal, as that part is coupled to the concrete data store we're dealing with and its capabilities.

Are you experiencing any concrete problem with this?

@vpavic vpavic self-assigned this Oct 3, 2019
@vpavic vpavic added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 3, 2019
@finke-ba
Copy link
Author

finke-ba commented Oct 3, 2019

@vpavic, thank you for the response.
My main problem that in my WebFlux application after logout I still have old session in DB and it's still possible to use this session. I mean if you save session cookie, logout and after that make a request with old cookie you will get previous session from db.
And I ended up in WebSession#changeSessionId which just create new session, but old session still exist and valid. I thought old session should be deleted or invalidated by default, without adding my custom logic somewhere.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 3, 2019
@vpavic
Copy link
Contributor

vpavic commented Oct 3, 2019

What's the actually ReactiveSessionRepository implementation you're using? Right now we have no information at all about your Spring Session setup. Can you provide a sample application that demonstrates the problem?

@vpavic vpavic added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Oct 3, 2019
@finke-ba
Copy link
Author

finke-ba commented Oct 3, 2019

I'm using ReactiveMongoOperationsSessionRepository. Yes, I could provide example , but it will take some time to make it.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 3, 2019
@vpavic
Copy link
Contributor

vpavic commented Oct 3, 2019

MongoDB implementation is handled by separate project - you should open an issue against spring-session-data-mongodb repo. Once you do that, feel free to post a link to that issue here.

I'm going to close this for now, if it turns out this is a problem in Spring Session core, we can always reopen the issue later on.

@vpavic vpavic closed this as completed Oct 3, 2019
@vpavic vpavic added for: external-project For an external project and not something we can fix and removed status: feedback-provided Feedback has been provided labels Oct 3, 2019
@finke-ba
Copy link
Author

finke-ba commented Oct 3, 2019

@vpavic could you tell me please why WebSession#changeSessionId it's not implemented like this:

@Override
public Mono<Void> changeSessionId() {
	return Mono.defer(() -> {
		this.session.changeSessionId();
		return invalidate().then(save());
	});
}

@finke-ba
Copy link
Author

finke-ba commented Oct 3, 2019

@vpavic
Copy link
Contributor

vpavic commented Oct 3, 2019

As explained in previous comment, this is a responsibility of ReactiveSessionRepository that SpringSessionWebSessionStore delegates to.

For example, in Redis implementation this project provides, this is handled by Redis rename command:

return ReactiveRedisSessionRepository.this.sessionRedisOperations.rename(originalSessionKey, sessionKey)
.and(replaceSessionId);

So the problem really is in MongoDB implementation, and should be reported in the appropriate project.

@finke-ba
Copy link
Author

finke-ba commented Oct 4, 2019

Okey, thank you for you help a lot!
I'll report this issue to spring-session-data-mongodb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

3 participants