Skip to content
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

[MM-54359] Implement session validation check #620

Merged
merged 3 commits into from
Jan 18, 2024
Merged

[MM-54359] Implement session validation check #620

merged 3 commits into from
Jan 18, 2024

Conversation

streamer45
Copy link
Collaborator

Summary

PR implements a session validation check to forcefully disconnect any calls client that has either their session revoked or expired.

Ticket Link

https://mattermost.atlassian.net/browse/MM-54359

@streamer45 streamer45 added 2: Dev Review Requires review by a core committer 3: Security Review labels Jan 16, 2024
@streamer45 streamer45 self-assigned this Jan 16, 2024
@streamer45 streamer45 added this to the v0.23.1 milestone Jan 16, 2024
@@ -48,6 +48,10 @@ const (
wsReconnectionTimeout = 10 * time.Second
)

var (
sessionAuthCheckInterval = 10 * time.Second
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esarafianou For performance reasons I wouldn't go lower than this, let me know if it's reasonable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally reasonable.

Copy link
Member

@cpoile cpoile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Just a non-blocking question.

continue
}

if s, appErr := p.API.GetSession(authSessionID); appErr != nil || time.Now().UnixMilli() >= s.ExpiresAt {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a sense of what kind of pressure this is going to put on the system?
Is there a batched version of getSession?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a sense of what kind of pressure this is going to put on the system?

Performance should be fairly good since we cache sessions so normally that call shouldn't be hitting the database but yeah that's a concern I had as well.

Is there a batched version of getSession?

I don't believe so, definitely not exposed to the plugin side anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpoile To add some context, in general I felt this to be the safest approach because otherwise we'd have to implement a plugin hook that triggers on session invalidation which can definitely improve performance but it's also much easier to mess up security wise.

If performance ever becomes a problem I'd probably go down that route.

@streamer45 streamer45 removed the 2: Dev Review Requires review by a core committer label Jan 16, 2024
@streamer45
Copy link
Collaborator Author

streamer45 commented Jan 16, 2024

Sent a fix e2e tests caught. We should also support sessions with a zero ExpiresAt which means no expiration.

@codecov-commenter
Copy link

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (2df6784) 0.00% compared to head (16aa090) 9.33%.

Files Patch % Lines
server/websocket.go 76.31% 8 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           main    #620      +/-   ##
=======================================
+ Coverage      0   9.33%   +9.33%     
=======================================
  Files         0      26      +26     
  Lines         0    5293    +5293     
=======================================
+ Hits          0     494     +494     
- Misses        0    4747    +4747     
- Partials      0      52      +52     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -379,7 +383,10 @@ func (p *Plugin) OnWebSocketDisconnect(connID, userID string) {
}
}

func (p *Plugin) wsReader(us *session, handlerID string) {
func (p *Plugin) wsReader(us *session, authSessionID, handlerID string) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a relevant PR in the mattermost repo that will be sending the authSessionID?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that's the one I mentioned in the internal thread: mattermost/mattermost#25928

server/websocket.go Show resolved Hide resolved
Copy link

@esarafianou esarafianou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@streamer45 streamer45 added the 3: Reviews Complete All reviewers have approved the pull request label Jan 18, 2024
@streamer45 streamer45 merged commit 738ae2b into main Jan 18, 2024
6 checks passed
@streamer45 streamer45 deleted the MM-54359 branch January 18, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants