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 #5121: Check if chat messages start with 'name: ' #5254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/network/protocols/server_lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,23 @@ void ServerLobby::handleChat(Event* event)
core::stringw message;
event->data().decodeString16(&message, 360/*max_len*/);

// Check if the message starts with "(the name of main profile): " to prevent
// impersonation, see #5121.
std::string message_utf8 = StringUtils::wideToUtf8(message);
std::string prefix = StringUtils::wideToUtf8(
event->getPeer()->getPlayerProfiles()[0]->getName()) + ": ";

if (!StringUtils::startsWith(message_utf8, prefix))
{
NetworkString* chat = getNetworkString();
chat->setSynchronous(true);
core::stringw warn = "Don't try to impersonate others!";
chat->addUInt8(LE_CHAT).encodeString16(warn);
event->getPeer()->sendPacket(chat, true/*reliable*/);
delete chat;
return;
}

KartTeam target_team = KART_TEAM_NONE;
if (event->data().size() > 0)
target_team = (KartTeam)event->data().getUInt8();
Expand Down