The Wayback Machine - https://web.archive.org/web/20210421081901/https://github.com/RocketChat/Rocket.Chat/pull/20815
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

[FIX] Quoted messages from message links when user has no permission #20815

Merged
merged 8 commits into from Feb 20, 2021

Conversation

@KevLehman
Copy link
Contributor

@KevLehman KevLehman commented Feb 18, 2021

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

@KevLehman KevLehman requested a review from sampaiodiego Feb 18, 2021
@sampaiodiego sampaiodiego changed the title Fix leaking messages [FIX] Quoted messages from message links Feb 18, 2021
app/oembed/server/jumpToMessage.js Outdated Show resolved Hide resolved
app/oembed/server/jumpToMessage.js Show resolved Hide resolved

// validates if user can see the message
// user has to belong to the room the message was first wrote in
const canAccessRoom = Meteor.call('canAccessRoom', jumpToMessage.rid, Meteor.userId());

This comment has been minimized.

@sampaiodiego

sampaiodiego Feb 19, 2021
Member

please try to avoid using Meteor methods, specially on server code. always check if there is a service that does the same and if you can't used async functions (like here), look for alternative functions or use Promise.await.

to check if a user has permission to access a room you can use canAccessRoom

This comment has been minimized.

@KevLehman

KevLehman Feb 19, 2021
Author Contributor

Done!

KevLehman and others added 3 commits Feb 19, 2021
Co-authored-by: Diego Sampaio <chinello@gmail.com>

// validates if user can see the message
// user has to belong to the room the message was first wrote in
const canAccessRoomForUser = canAccessRoom({ _id: jumpToMessage.rid }, Meteor.user());

This comment has been minimized.

@sampaiodiego

sampaiodiego Feb 19, 2021
Member

I think you'll need to send a complete Room object to canAccessRoom..

I'd also recommend to store Meteor.user() in a variable instead of calling it inside the loop.

This comment has been minimized.

@KevLehman

KevLehman Feb 19, 2021
Author Contributor

Regarding this one, I noticed that in other places they were retrieving Rooms.findById(...., { _id: 1 }). That will exclude other fields and returning just the ID as an object. This mimics the same behavior to avoid calling the database n times. (And it looks like its working haha)

Regarding the Meteor.user I didn't know it was an expensive operation, I'll move it to the top.

// validates if user can see the message
// user has to belong to the room the message was first wrote in
const canAccessRoomForUser = canAccessRoom({ _id: jumpToMessage.rid }, Meteor.user());
if (jumpToMessage && canAccessRoomForUser) {

This comment has been minimized.

@sampaiodiego

sampaiodiego Feb 19, 2021
Member

why not having a shortcut as others here? 😬

Suggested change
if (jumpToMessage && canAccessRoomForUser) {
if (!canAccessRoomForUser) {
return;
}

This comment has been minimized.

@KevLehman

KevLehman Feb 19, 2021
Author Contributor

Ah, yes 🤔 since we are checking for jumpToMessage some lines above, it makes sense to use the shortcircuit here. Nice catch!

KevLehman and others added 3 commits Feb 19, 2021
@sampaiodiego sampaiodiego changed the title [FIX] Quoted messages from message links [FIX] Quoted messages from message links when user has no permission Feb 20, 2021
@sampaiodiego sampaiodiego merged commit c0f67ec into develop Feb 20, 2021
13 checks passed
13 checks passed
build
Details
CodeQL-Build CodeQL-Build
Details
CodeQL-Build CodeQL-Build
Details
build-image-pr
Details
test (12.18.4, 3.4)
Details
test (12.18.4, 3.6)
Details
test (12.18.4, 4.0)
Details
deploy
Details
image-build
Details
services-image-build
Details
CodeQL No new or fixed alerts
Details
LGTM analysis: JavaScript No new or fixed alerts
Details
security/snyk (rodrigok) No manifest changes detected in 5 projects
Details
@sampaiodiego sampaiodiego deleted the fix-leaking-messages branch Feb 20, 2021
@sampaiodiego sampaiodiego mentioned this pull request Feb 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants