Skip to content

Commit

Permalink
Prevent blacklisted users from quoting messages
Browse files Browse the repository at this point in the history
  • Loading branch information
7PH committed Mar 16, 2024
1 parent 6e1761e commit 3c67a7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
20 changes: 10 additions & 10 deletions app/server/plugins/core/global/PrivateMessagePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ export class PrivateMessagePlugin extends GlobalPlugin {

async run(alias: string, param: string, connection: Connection): Promise<void> {
switch (alias) {
case 'pm':
await this.handlePM(param, connection);
break;
case 'pm':
await this.handlePM(param, connection);
break;

case 'pmadd':
await this.handlePMAdd(param, connection);
break;
case 'pmadd':
await this.handlePMAdd(param, connection);
break;

case 'pmleave':
await this.handlePMLeave(param, connection);
break;
case 'pmleave':
await this.handlePMLeave(param, connection);
break;
}
}

Expand Down Expand Up @@ -104,7 +104,7 @@ export class PrivateMessagePlugin extends GlobalPlugin {
throw new Error('You can not add yourself to a private room');
}
if (BlacklistPlugin.hasBlacklisted(session.user, connection.session.user.username)) {
throw new Error(`User ${param} has blacklisted you. You can not add him to this private room`);
throw new Error(`User ${session.user.username} has blacklisted you. You can not add him to this private room`);
}
if (room.whitelist.indexOf(session.identifier) !== -1) {
throw new Error(`User ${param} is already in this private room`);
Expand Down
8 changes: 7 additions & 1 deletion app/server/plugins/core/room/MessagePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RoomPlugin } from '../../RoomPlugin';
import { DatabaseHelper } from '../../../skychat/DatabaseHelper';
import SQL from 'sql-template-strings';
import { MessageLimiterPlugin } from '../../security_extra/MessageLimiterPlugin';
import { BlacklistPlugin } from '../global/BlacklistPlugin';

export class MessagePlugin extends RoomPlugin {
static readonly commandName = 'message';
Expand Down Expand Up @@ -38,7 +39,12 @@ export class MessagePlugin extends RoomPlugin {
// Otherwise, try to find the quoted message in the database
quoted = quoted || (await MessageController.getMessageById(quoteId));

// If quote found, remote the quote string from the message
// If author has blacklisted the user, we don't allow the quote
if (quoted && BlacklistPlugin.hasBlacklisted(quoted?.user, connection.session.user.username)) {
throw new Error(`User ${param} has blacklisted you. You can not quote his messages`);
}

// If quote found, remove the quote string from the message
if (quoted) {
content = content.slice(quoteMatch[0].length);
}
Expand Down

0 comments on commit 3c67a7f

Please sign in to comment.