aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/game/Chat/Hyperlinks.cpp77
-rw-r--r--src/server/game/Chat/Hyperlinks.h2
-rw-r--r--src/server/game/Handlers/ChatHandler.cpp68
-rw-r--r--src/server/game/Server/WorldSession.cpp16
-rw-r--r--src/server/game/Server/WorldSession.h3
-rw-r--r--src/server/worldserver/worldserver.conf.dist2
6 files changed, 56 insertions, 112 deletions
diff --git a/src/server/game/Chat/Hyperlinks.cpp b/src/server/game/Chat/Hyperlinks.cpp
index dec3da491be..8f9f5153328 100644
--- a/src/server/game/Chat/Hyperlinks.cpp
+++ b/src/server/game/Chat/Hyperlinks.cpp
@@ -675,77 +675,46 @@ static bool ValidateLinkInfo(HyperlinkInfo const& info)
}
// Validates all hyperlinks and control sequences contained in str
-bool Trinity::Hyperlinks::ValidateLinks(std::string& str)
+bool Trinity::Hyperlinks::CheckAllLinks(std::string const& str)
{
- bool allValid = true;
- std::string::size_type pos = std::string::npos;
- // Step 1: Strip all control sequences except ||, |H, |h, |c and |r
- do
+ // Step 1: Disallow all control sequences except ||, |H, |h, |c and |r
{
- if ((pos = str.rfind('|', pos)) == std::string::npos)
- break;
- if (pos && str[pos - 1] == '|')
+ std::string::size_type pos = 0;
+ while ((pos = str.find('|', pos)) != std::string::npos)
{
- --pos;
- continue;
+ char next = str[pos + 1];
+ if (next == 'H' || next == 'h' || next == 'c' || next == 'r' || next == '|')
+ pos += 2;
+ else
+ return false;
}
- char next = str[pos + 1];
- if (next == 'H' || next == 'h' || next == 'c' || next == 'r')
- continue;
-
- allValid = false;
- str.erase(pos, 2);
- } while (pos--);
-
+ }
+
// Step 2: Parse all link sequences
// They look like this: |c<color>|H<linktag>:<linkdata>|h[<linktext>]|h|r
// - <color> is 8 hex characters AARRGGBB
// - <linktag> is arbitrary length [a-z_]
// - <linkdata> is arbitrary length, no | contained
// - <linktext> is printable
- pos = 0;
- while (pos < str.size() && (pos = str.find('|', pos)) != std::string::npos)
{
- if (str[pos + 1] == '|') // this is an escaped pipe character (||)
+ std::string::size_type pos = 0;
+ while ((pos = str.find('|', pos)) != std::string::npos)
{
- pos += 2;
- continue;
- }
-
- HyperlinkInfo info = ParseHyperlink(str.c_str() + pos);
- if (!info)
- { // cannot be parsed at all, so we'll need to cut it out entirely
- // find the next start of a link
- std::string::size_type next = str.find("|c", pos + 1);
- // then backtrack to the previous return control sequence
- std::string::size_type end = str.rfind("|r", next);
- if (end == std::string::npos || end <= pos) // there is no potential end tag, remove everything after pos (up to next, if available)
+ if (str[pos + 1] == '|') // this is an escaped pipe character (||)
{
- if (next == std::string::npos)
- str.erase(pos);
- else
- str.erase(pos, next - pos);
+ pos += 2;
+ continue;
}
- else
- str.erase(pos, end - pos + 2);
- allValid = false;
- continue;
- }
+ HyperlinkInfo info = ParseHyperlink(str.c_str() + pos);
+ if (!info || !ValidateLinkInfo(info))
+ return false;
- // ok, link parsed successfully - now validate it based on the tag
- if (!ValidateLinkInfo(info))
- {
- // invalid link info, replace with just text
- str.replace(pos, (info.next - str.c_str()) - pos, str, info.text.first - str.c_str(), info.text.second);
- allValid = false;
- continue;
+ // tag is fine, find the next one
+ pos = info.next - str.c_str();
}
-
- // tag is fine, find the next one
- pos = info.next - str.c_str();
}
- // all tags validated
- return allValid;
+ // all tags are valid
+ return true;
}
diff --git a/src/server/game/Chat/Hyperlinks.h b/src/server/game/Chat/Hyperlinks.h
index 7108be73372..65d6d595f0a 100644
--- a/src/server/game/Chat/Hyperlinks.h
+++ b/src/server/game/Chat/Hyperlinks.h
@@ -465,7 +465,7 @@ struct HyperlinkInfo
std::pair<char const*, size_t> const text;
};
HyperlinkInfo TC_GAME_API ParseHyperlink(char const* pos);
-bool TC_GAME_API ValidateLinks(std::string&);
+bool TC_GAME_API CheckAllLinks(std::string const&);
}
}
diff --git a/src/server/game/Handlers/ChatHandler.cpp b/src/server/game/Handlers/ChatHandler.cpp
index f6a39ea12e8..bad1d613e0f 100644
--- a/src/server/game/Handlers/ChatHandler.cpp
+++ b/src/server/game/Handlers/ChatHandler.cpp
@@ -29,7 +29,6 @@
#include "Group.h"
#include "Guild.h"
#include "GuildMgr.h"
-#include "Hyperlinks.h"
#include "Language.h"
#include "LanguageMgr.h"
#include "Log.h"
@@ -206,6 +205,9 @@ void WorldSession::HandleChatMessage(ChatMsg type, Language lang, std::string ms
return;
}
+ if (msg.size() > 255)
+ return;
+
// Strip invisible characters for non-addon messages
if (sWorld->getBoolConfig(CONFIG_CHAT_FAKE_MESSAGE_PREVENTING))
StripInvisibleChars(msg);
@@ -216,20 +218,7 @@ void WorldSession::HandleChatMessage(ChatMsg type, Language lang, std::string ms
if (ChatHandler(this).ParseCommands(msg.c_str()))
return;
- bool validMessage = Trinity::Hyperlinks::ValidateLinks(msg);
- if (!validMessage)
- {
- TC_LOG_ERROR("network", "Player %s (%s) sent a chatmessage with an invalid link - corrected", GetPlayer()->GetName().c_str(),
- GetPlayer()->GetGUID().ToString().c_str());
-
- if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
- {
- KickPlayer();
- return;
- }
- }
-
- if (msg.length() > 255)
+ if (!ValidateHyperlinksAndMaybeKick(msg))
return;
switch (type)
@@ -468,19 +457,6 @@ void WorldSession::HandleChatAddonMessage(ChatMsg type, std::string prefix, std:
if (prefix == AddonChannelCommandHandler::PREFIX && AddonChannelCommandHandler(this).ParseCommands(text.c_str()))
return;
- bool validMessage = Trinity::Hyperlinks::ValidateLinks(text);
- if (!validMessage)
- {
- TC_LOG_ERROR("network", "Player %s (%s) sent a chatmessage with an invalid link - corrected", GetPlayer()->GetName().c_str(),
- GetPlayer()->GetGUID().ToString().c_str());
-
- if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
- {
- KickPlayer();
- return;
- }
- }
-
if (text.length() > 255)
return;
@@ -558,24 +534,14 @@ void WorldSession::HandleChatMessageAFKOpcode(WorldPackets::Chat::ChatMessageAFK
if (sender->IsInCombat())
return;
+ if (chatMessageAFK.Text.length() > 255)
+ return;
+
// Strip invisible characters for non-addon messages
if (sWorld->getBoolConfig(CONFIG_CHAT_FAKE_MESSAGE_PREVENTING))
StripInvisibleChars(chatMessageAFK.Text);
- bool validMessage = Trinity::Hyperlinks::ValidateLinks(chatMessageAFK.Text);
- if (!validMessage)
- {
- TC_LOG_ERROR("network", "Player %s (%s) sent a chatmessage with an invalid link - corrected", GetPlayer()->GetName().c_str(),
- GetPlayer()->GetGUID().ToString().c_str());
-
- if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
- {
- KickPlayer();
- return;
- }
- }
-
- if (chatMessageAFK.Text.length() > 255)
+ if (!ValidateHyperlinksAndMaybeKick(chatMessageAFK.Text))
return;
if (sender->HasAura(GM_SILENCE_AURA))
@@ -614,24 +580,14 @@ void WorldSession::HandleChatMessageDNDOpcode(WorldPackets::Chat::ChatMessageDND
if (sender->IsInCombat())
return;
+ if (chatMessageDND.Text.length() > 255)
+ return;
+
// Strip invisible characters for non-addon messages
if (sWorld->getBoolConfig(CONFIG_CHAT_FAKE_MESSAGE_PREVENTING))
StripInvisibleChars(chatMessageDND.Text);
- bool validMessage = Trinity::Hyperlinks::ValidateLinks(chatMessageDND.Text);
- if (!validMessage)
- {
- TC_LOG_ERROR("network", "Player %s (%s) sent a chatmessage with an invalid link - corrected", GetPlayer()->GetName().c_str(),
- GetPlayer()->GetGUID().ToString().c_str());
-
- if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
- {
- KickPlayer();
- return;
- }
- }
-
- if (chatMessageDND.Text.length() > 255)
+ if (!ValidateHyperlinksAndMaybeKick(chatMessageDND.Text))
return;
if (sender->HasAura(GM_SILENCE_AURA))
diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp
index f6ccf775332..885a20666f2 100644
--- a/src/server/game/Server/WorldSession.cpp
+++ b/src/server/game/Server/WorldSession.cpp
@@ -34,7 +34,9 @@
#include "Group.h"
#include "Guild.h"
#include "GuildMgr.h"
+#include "Hyperlinks.h"
#include "IpAddress.h"
+#include "Log.h"
#include "Map.h"
#include "Metric.h"
#include "MiscPackets.h"
@@ -655,6 +657,20 @@ void WorldSession::KickPlayer()
}
}
+bool WorldSession::ValidateHyperlinksAndMaybeKick(std::string const& str)
+{
+ if (Trinity::Hyperlinks::CheckAllLinks(str))
+ return true;
+
+ TC_LOG_ERROR("network", "Player %s (%s) sent a message with an invalid link:\n%s", GetPlayer()->GetName().c_str(),
+ GetPlayer()->GetGUID().ToString().c_str(), str.c_str());
+
+ if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK))
+ KickPlayer();
+
+ return false;
+}
+
void WorldSession::SendNotification(char const* format, ...)
{
if (format)
diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
index 8f987ff0e4b..7ed836c5ea1 100644
--- a/src/server/game/Server/WorldSession.h
+++ b/src/server/game/Server/WorldSession.h
@@ -1009,6 +1009,9 @@ class TC_GAME_API WorldSession
void LogoutPlayer(bool save);
void KickPlayer();
+ // 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);
void QueuePacket(WorldPacket* new_packet);
bool Update(uint32 diff, PacketFilter& updater);
diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist
index ca5cbd34d5e..2eec02e5353 100644
--- a/src/server/worldserver/worldserver.conf.dist
+++ b/src/server/worldserver/worldserver.conf.dist
@@ -1951,7 +1951,7 @@ ChatStrictLinkChecking.Severity = 0
# ChatStrictLinkChecking.Kick
# Description: Defines what should be done if a message containing invalid control characters
# is received.
-# Default: 0 - (Process sanitized message normally)
+# Default: 0 - (Silently ignore message)
# 1 - (Ignore message and kick player)
ChatStrictLinkChecking.Kick = 0