Pinning leaks message content
The message pinning function did not validate that the message being pinned belonged to a room the user was subscribed to, and it accepted arbitrary JavaScript objects as input. An attacker with access to any room could pin a message from a private room and receive its content in the response.
- Triaged in 12 hours
- Fixed in 39 days
- Disclosed after 3.6 years
Summary: Improper input validation allows pinning of arbitrary messages (in private channels), leaking the message content back to the sender.
Description:
Message pinning was found to lack input data validation, so that arbitrary messages can be pinned and leaked back to an unauthorized client.
Meteor.methods({
pinMessage(message) {
if (!Meteor.userId()) {
toastr.error(TAPi18n.__('error-not-authorized'));
return false;
}
if (!settings.get('Message_AllowPinning')) {
toastr.error(TAPi18n.__('pinning-not-allowed'));
return false;
}
if (Subscriptions.findOne({ rid: message.rid }) == null) {
toastr.error(TAPi18n.__('error-pinning-message'));
return false;
}
toastr.success(TAPi18n.__('Message_has_been_pinned'));
return ChatMessage.update({
_id: message._id,
}, {
$set: {
pinned: true,
},
});
},
// ...
});
The Meteor.method pinMessage accepts a message object as input with _id and rid keys.
With a known Message ID and any Room ID that is accessible by the attacker, the check room subscriptions can be circumvented, because the target chat message is not validated to be in the same room as validated with Subscriptions.findOne({ rid: message.rid }.
In addition to that the pinMessage function accepts JavaScript objects that are then directly forwarded to the MongoDB model, allowing attackers to use regular expressions to improve guessing of message IDs.
Meteor.call("pinMessage", {
_id: { $regex: /.*/ },
rid: "<ACCESSIBLE_ROOM_ID>"
}, (...args) => console.log(...args));
The Meteor.call return data contains the message content, so that an arbitrary user with access to any channel can leak individual messages outside of their accessible channels.
Releases Affected:
- 3.9.10 / develop
Steps To Reproduce (from initial installation to vulnerability):
(Add details for how we can reproduce the issue)
- Open Rocket.Chat
- Find any accessible Room ID (for instance from channel avatar URL)
- Open Web Inspector
- Execute pinMessage Meteor.call and receive message content in return callback
Suggested mitigation
- Check message object data types
- Query the target
ridalong with the updated message_id.
diff --git a/app/message-pin/client/pinMessage.js b/app/message-pin/client/pinMessage.js
index 9fbc2f778..c360c5d9c 100644
--- a/app/message-pin/client/pinMessage.js
+++ b/app/message-pin/client/pinMessage.js
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
+import { check } from 'meteor/check';
import toastr from 'toastr';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
@@ -7,6 +8,8 @@ import { ChatMessage, Subscriptions } from '../../models';
Meteor.methods({
pinMessage(message) {
+ check(message._id, String);
+ check(message.rid, String);
if (!Meteor.userId()) {
toastr.error(TAPi18n.__('error-not-authorized'));
return false;
@@ -22,6 +25,7 @@ Meteor.methods({
toastr.success(TAPi18n.__('Message_has_been_pinned'));
return ChatMessage.update({
_id: message._id,
+ rid: message.rid
}, {
$set: {
pinned: true,
@@ -29,6 +33,8 @@ Meteor.methods({
});
},
unpinMessage(message) {
+ check(message._id, String);
+ check(message.rid, String);
if (!Meteor.userId()) {
toastr.error(TAPi18n.__('error-not-authorized'));
return false;
@@ -44,6 +50,7 @@ Meteor.methods({
toastr.success(TAPi18n.__('Message_has_been_unpinned'));
return ChatMessage.update({
_id: message._id,
+ rid: message.rid
}, {
$set: {
pinned: false,
Impact
Content of arbitrary (private) messages can be leaked by any client with access to at least one room.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The pinMessage method checked the user's subscription to the supplied room ID but did not verify that the target message ID belonged to that same room, and it also failed to validate the input types.
Impact
Content of arbitrary (private) messages can be leaked by any client with access to at least one room.
What the attacker needed
Access to at least one room; known message ID (or regex guessing)
The fix
The fix should validate that the message ID and room ID are strings and include the room ID in the database update query so the message must belong to that room.
How it was found
- Open Rocket.Chat
- Find any accessible Room ID (for instance from channel avatar URL)
- Open Web Inspector
- Execute pinMessage Meteor.call and receive message content in return callback
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a chat app, you should only be able to pin messages in rooms you are a member of. The pinning function checked that you were in some room, but not that the message you tried to pin was in that same room. By sending a request with a message ID from a private room and a room ID they did have access to, an attacker could trick the server into returning the private message's content.
What is IDOR?
One user can read or change another user's data, usually by changing an identifier the server trusts without checking who is asking. One of the most paid bug classes on web programs.