Core/Chat: Disallow hyperlinks from being inserted in various guild-related freetext fields (the client already blocks this)

This commit is contained in:
treeston
2020-03-15 19:47:55 +01:00
parent 3c4133a2ff
commit 01b2ac3ed4
3 changed files with 65 additions and 0 deletions

View File

@@ -162,6 +162,12 @@ void WorldSession::HandleGuildMOTDOpcode(WorldPacket& recvPacket)
TC_LOG_DEBUG("guild", "CMSG_GUILD_MOTD [%s]: MOTD: %s", GetPlayerInfo().c_str(), motd.c_str());
if (!DisallowHyperlinksAndMaybeKick(motd))
return;
if (motd.size() > 128)
return;
if (Guild* guild = GetPlayer()->GetGuild())
guild->HandleSetMOTD(this, motd);
}
@@ -175,6 +181,12 @@ void WorldSession::HandleGuildSetPublicNoteOpcode(WorldPacket& recvPacket)
TC_LOG_DEBUG("guild", "CMSG_GUILD_SET_PUBLIC_NOTE [%s]: Target: %s, Note: %s",
GetPlayerInfo().c_str(), playerName.c_str(), note.c_str());
if (!DisallowHyperlinksAndMaybeKick(note))
return;
if (note.size() > 31)
return;
if (normalizePlayerName(playerName))
if (Guild* guild = GetPlayer()->GetGuild())
guild->HandleSetMemberNote(this, playerName, note, false);
@@ -189,6 +201,12 @@ void WorldSession::HandleGuildSetOfficerNoteOpcode(WorldPacket& recvPacket)
TC_LOG_DEBUG("guild", "CMSG_GUILD_SET_OFFICER_NOTE [%s]: Target: %s, Note: %s",
GetPlayerInfo().c_str(), playerName.c_str(), note.c_str());
if (!DisallowHyperlinksAndMaybeKick(note))
return;
if (note.size() > 31)
return;
if (normalizePlayerName(playerName))
if (Guild* guild = GetPlayer()->GetGuild())
guild->HandleSetMemberNote(this, playerName, note, true);
@@ -210,6 +228,12 @@ void WorldSession::HandleGuildRankOpcode(WorldPacket& recvPacket)
TC_LOG_DEBUG("guild", "CMSG_GUILD_RANK [%s]: Rank: %s (%u)", GetPlayerInfo().c_str(), rankName.c_str(), rankId);
if (!DisallowHyperlinksAndMaybeKick(rankName))
return;
if (rankName.size() > 15)
return;
Guild* guild = GetPlayer()->GetGuild();
if (!guild)
{
@@ -240,6 +264,12 @@ void WorldSession::HandleGuildAddRankOpcode(WorldPacket& recvPacket)
TC_LOG_DEBUG("guild", "CMSG_GUILD_ADD_RANK [%s]: Rank: %s", GetPlayerInfo().c_str(), rankName.c_str());
if (!DisallowHyperlinksAndMaybeKick(rankName))
return;
if (rankName.size() > 15)
return;
if (Guild* guild = GetPlayer()->GetGuild())
guild->HandleAddNewRank(this, rankName);
}
@@ -259,6 +289,12 @@ void WorldSession::HandleGuildChangeInfoTextOpcode(WorldPacket& recvPacket)
TC_LOG_DEBUG("guild", "CMSG_GUILD_INFO_TEXT [%s]: %s", GetPlayerInfo().c_str(), info.c_str());
if (!DisallowHyperlinksAndMaybeKick(info))
return;
if (info.size() > 500)
return;
if (Guild* guild = GetPlayer()->GetGuild())
guild->HandleSetInfo(this, info);
}
@@ -485,6 +521,12 @@ void WorldSession::HandleGuildBankUpdateTab(WorldPacket& recvData)
recvData >> guid >> tabId >> name >> icon;
if (!DisallowHyperlinksAndMaybeKick(name))
return;
if ((name.size() > 16) || (icon.size() > 128))
return;
TC_LOG_DEBUG("guild", "CMSG_GUILD_BANK_UPDATE_TAB [%s]: [%s], TabId: %u, Name: %s, Icon: %s"
, GetPlayerInfo().c_str(), guid.ToString().c_str(), tabId, name.c_str(), icon.c_str());
@@ -522,6 +564,12 @@ void WorldSession::HandleSetGuildBankTabText(WorldPacket &recvData)
std::string text;
recvData >> tabId >> text;
if (!DisallowHyperlinksAndMaybeKick(text))
return;
if (text.size() > 500)
return;
TC_LOG_DEBUG("guild", "CMSG_SET_GUILD_BANK_TEXT [%s]: TabId: %u, Text: %s", GetPlayerInfo().c_str(), tabId, text.c_str());
if (Guild* guild = GetPlayer()->GetGuild())

View File

@@ -619,6 +619,20 @@ bool WorldSession::ValidateHyperlinksAndMaybeKick(std::string const& str)
return false;
}
bool WorldSession::DisallowHyperlinksAndMaybeKick(std::string const& str)
{
if (str.find('|') == std::string::npos)
return true;
TC_LOG_ERROR("network", "Player %s (GUID: %u) sent a message which illegally contained a hyperlink:\n%s", GetPlayer()->GetName().c_str(),
GetPlayer()->GetGUID().GetCounter(), str.c_str());
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
KickPlayer();
return false;
}
void WorldSession::SendNotification(const char *format, ...)
{
if (format)

View File

@@ -369,6 +369,9 @@ class TC_GAME_API WorldSession
// Returns true if all contained hyperlinks are valid
// May kick player on false depending on world config (handler should abort)
bool ValidateHyperlinksAndMaybeKick(std::string const& str);
// Returns true if the message contains no hyperlinks
// May kick player on false depending on world config (handler should abort)
bool DisallowHyperlinksAndMaybeKick(std::string const& str);
void QueuePacket(WorldPacket* new_packet);
bool Update(uint32 diff, PacketFilter& updater);