aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sadie Powell2021-11-24 07:17:50 +0000
committerGravatar Sadie Powell2021-11-24 07:17:50 +0000
commit2ec53e10ee5325df12586c72471efabb07cb9d70 (patch)
tree7f06c35178be0c65048d9f2ff30b73b2bebb36a5 /src
parentDon't allow routing INFO to remote servers. (diff)
parentMake parsing websocket proxy headers more robust. (diff)
Merge branch 'insp3' into master.
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp1
-rw-r--r--src/modules/m_anticaps.cpp6
-rw-r--r--src/modules/m_banredirect.cpp32
-rw-r--r--src/modules/m_httpd_stats.cpp4
-rw-r--r--src/modules/m_messageflood.cpp6
-rw-r--r--src/modules/m_repeat.cpp7
-rw-r--r--src/modules/m_timedbans.cpp6
-rw-r--r--src/modules/m_websocket.cpp20
-rw-r--r--src/users.cpp39
9 files changed, 72 insertions, 49 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index ed1463147..86329355e 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -274,6 +274,7 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
me->maxconnwarn = tag->getBool("maxconnwarn", me->maxconnwarn);
me->limit = tag->getUInt("limit", me->limit);
me->resolvehostnames = tag->getBool("resolvehostnames", me->resolvehostnames);
+ me->uniqueusername = tag->getBool("uniqueusername", me->uniqueusername);
me->password = tag->getString("password", me->password);
me->passwordhash = tag->getString("hash", me->passwordhash);
diff --git a/src/modules/m_anticaps.cpp b/src/modules/m_anticaps.cpp
index 619d87158..9972aca32 100644
--- a/src/modules/m_anticaps.cpp
+++ b/src/modules/m_anticaps.cpp
@@ -155,6 +155,7 @@ class ModuleAntiCaps final
: public Module
{
private:
+ ChanModeReference banmode;
CheckExemption::EventProvider exemptionprov;
std::bitset<UCHAR_MAX + 1> uppercase;
std::bitset<UCHAR_MAX + 1> lowercase;
@@ -167,8 +168,8 @@ class ModuleAntiCaps final
banmask.append(user->GetDisplayedHost());
Modes::ChangeList changelist;
- changelist.push_add(ServerInstance->Modes.FindMode('b', MODETYPE_CHANNEL), banmask);
- ServerInstance->Modes.Process(ServerInstance->FakeClient, channel, NULL, changelist);
+ changelist.push_add(*banmode, banmask);
+ ServerInstance->Modes.Process(ServerInstance->FakeClient, channel, nullptr, changelist);
}
void InformUser(Channel* channel, User* user, const std::string& message)
@@ -179,6 +180,7 @@ class ModuleAntiCaps final
public:
ModuleAntiCaps()
: Module(VF_VENDOR | VF_COMMON, "Adds channel mode B (anticaps) which allows channels to block messages which are excessively capitalised.")
+ , banmode(this, "ban")
, exemptionprov(this)
, mode(this)
{
diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp
index cfe813b8b..ac86d63c7 100644
--- a/src/modules/m_banredirect.cpp
+++ b/src/modules/m_banredirect.cpp
@@ -52,13 +52,14 @@ typedef std::vector<BanRedirectEntry> BanRedirectList;
class BanRedirect final
: public ModeWatcher
{
- ChanModeReference ban;
public:
- SimpleExtItem<BanRedirectList> extItem;
+ ChanModeReference banmode;
+ SimpleExtItem<BanRedirectList> redirectlist;
+
BanRedirect(Module* parent)
: ModeWatcher(parent, "ban", MODETYPE_CHANNEL)
- , ban(parent, "ban")
- , extItem(parent, "banredirect", ExtensionItem::EXT_CHANNEL)
+ , banmode(parent, "ban")
+ , redirectlist(parent, "banredirect", ExtensionItem::EXT_CHANNEL)
{
}
@@ -85,7 +86,7 @@ class BanRedirect final
if (change.param.find('#') == std::string::npos)
return true;
- ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+ ListModeBase* banlm = static_cast<ListModeBase*>(*banmode);
unsigned long maxbans = banlm->GetLimit(channel);
ListModeBase::ModeList* list = banlm->GetList(channel);
if (list && change.adding && maxbans <= list->size())
@@ -184,11 +185,11 @@ class BanRedirect final
if (change.adding)
{
/* It's a properly valid redirecting ban, and we're adding it */
- redirects = extItem.Get(channel);
+ redirects = redirectlist.Get(channel);
if (!redirects)
{
redirects = new BanRedirectList;
- extItem.Set(channel, redirects);
+ redirectlist.Set(channel, redirects);
}
else
{
@@ -215,7 +216,7 @@ class BanRedirect final
else
{
/* Removing a ban, if there's no extensible there are no redirecting bans and we're fine. */
- redirects = extItem.Get(channel);
+ redirects = redirectlist.Get(channel);
if (redirects)
{
/* But there were, so we need to remove the matching one if there is one */
@@ -228,7 +229,7 @@ class BanRedirect final
if(redirects->empty())
{
- extItem.Unset(channel);
+ redirectlist.Unset(channel);
}
break;
@@ -250,7 +251,7 @@ class ModuleBanRedirect final
: public Module
{
private:
- BanRedirect re;
+ BanRedirect banwatcher;
bool nofollow = false;
ChanModeReference limitmode;
ChanModeReference redirectmode;
@@ -258,7 +259,7 @@ class ModuleBanRedirect final
public:
ModuleBanRedirect()
: Module(VF_VENDOR | VF_COMMON, "Allows specifying a channel to redirect a banned user to in the ban mask.")
- , re(this)
+ , banwatcher(this)
, limitmode(this, "limit")
, redirectmode(this, "redirect")
{
@@ -269,18 +270,17 @@ class ModuleBanRedirect final
if (type == ExtensionItem::EXT_CHANNEL)
{
Channel* chan = static_cast<Channel*>(item);
- BanRedirectList* redirects = re.extItem.Get(chan);
+ BanRedirectList* redirects = banwatcher.redirectlist.Get(chan);
if(redirects)
{
- ModeHandler* ban = ServerInstance->Modes.FindMode('b', MODETYPE_CHANNEL);
Modes::ChangeList changelist;
for (auto& redirect : *redirects)
- changelist.push_remove(ban, redirect.targetchan.insert(0, redirect.banmask));
+ changelist.push_remove(*banwatcher.banmode, redirect.targetchan.insert(0, redirect.banmask));
for (const auto& redirect : *redirects)
- changelist.push_add(ban, redirect.banmask);
+ changelist.push_add(*banwatcher.banmode, redirect.banmask);
ServerInstance->Modes.Process(ServerInstance->FakeClient, chan, NULL, changelist, ModeParser::MODE_LOCALONLY);
}
@@ -291,7 +291,7 @@ class ModuleBanRedirect final
{
if (!override && chan)
{
- BanRedirectList* redirects = re.extItem.Get(chan);
+ BanRedirectList* redirects = banwatcher.redirectlist.Get(chan);
if (redirects)
{
diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp
index bcbcfba81..5d35d6fdf 100644
--- a/src/modules/m_httpd_stats.cpp
+++ b/src/modules/m_httpd_stats.cpp
@@ -210,7 +210,7 @@ namespace Stats
{
data << "<user>";
data << "<nickname>" << u->nick << "</nickname><uuid>" << u->uuid << "</uuid><realhost>"
- << u->GetRealHost() << "</realhost><displayhost>" << u->GetDisplayedHost() << "</displayhost><realname>"
+ << Sanitize(u->GetRealHost()) << "</realhost><displayhost>" << Sanitize(u->GetDisplayedHost()) << "</displayhost><realname>"
<< Sanitize(u->GetRealName()) << "</realname><server>" << u->server->GetName() << "</server><signon>"
<< u->signon << "</signon><age>" << u->age << "</age>";
@@ -229,7 +229,7 @@ namespace Stats
<< lu->GetClass()->GetName() << "</connectclass><lastmsg>"
<< lu->idle_lastmsg << "</lastmsg>";
- data << "<ipaddress>" << u->GetIPString() << "</ipaddress>";
+ data << "<ipaddress>" << Sanitize(u->GetIPString()) << "</ipaddress>";
DumpMeta(data, u);
diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp
index cab7a9879..4149e9dc8 100644
--- a/src/modules/m_messageflood.cpp
+++ b/src/modules/m_messageflood.cpp
@@ -115,6 +115,7 @@ class ModuleMsgFlood final
, public CTCTags::EventListener
{
private:
+ ChanModeReference banmode;
CheckExemption::EventProvider exemptionprov;
MsgFlood mf;
double notice;
@@ -125,6 +126,7 @@ private:
ModuleMsgFlood()
: Module(VF_VENDOR, "Adds channel mode f (flood) which helps protect against spammers which mass-message channels.")
, CTCTags::EventListener(this)
+ , banmode(this, "ban")
, exemptionprov(this)
, mf(this)
{
@@ -161,8 +163,8 @@ private:
if (f->ban)
{
Modes::ChangeList changelist;
- changelist.push_add(ServerInstance->Modes.FindMode('b', MODETYPE_CHANNEL), "*!*@" + user->GetDisplayedHost());
- ServerInstance->Modes.Process(ServerInstance->FakeClient, dest, NULL, changelist);
+ changelist.push_add(*banmode, "*!*@" + user->GetDisplayedHost());
+ ServerInstance->Modes.Process(ServerInstance->FakeClient, dest, nullptr, changelist);
}
const std::string kickMessage = "Channel flood triggered (trigger is " + ConvToStr(f->lines) +
diff --git a/src/modules/m_repeat.cpp b/src/modules/m_repeat.cpp
index f88f2552b..8b47d5c4b 100644
--- a/src/modules/m_repeat.cpp
+++ b/src/modules/m_repeat.cpp
@@ -356,12 +356,15 @@ class RepeatMode final
class RepeatModule final
: public Module
{
+ private:
+ ChanModeReference banmode;
CheckExemption::EventProvider exemptionprov;
RepeatMode rm;
public:
RepeatModule()
: Module(VF_VENDOR | VF_COMMON, "Adds channel mode E (repeat) which helps protect against spammers which spam the same message repeatedly.")
+ , banmode(this, "ban")
, exemptionprov(this)
, rm(this)
{
@@ -404,8 +407,8 @@ class RepeatModule final
if (settings->Action == ChannelSettings::ACT_BAN)
{
Modes::ChangeList changelist;
- changelist.push_add(ServerInstance->Modes.FindMode('b', MODETYPE_CHANNEL), "*!*@" + user->GetDisplayedHost());
- ServerInstance->Modes.Process(ServerInstance->FakeClient, chan, NULL, changelist);
+ changelist.push_add(*banmode, "*!*@" + user->GetDisplayedHost());
+ ServerInstance->Modes.Process(ServerInstance->FakeClient, chan, nullptr, changelist);
}
memb->chan->KickUser(ServerInstance->FakeClient, user, rm.GetKickMessage());
diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp
index e6a2712d3..65db00b88 100644
--- a/src/modules/m_timedbans.cpp
+++ b/src/modules/m_timedbans.cpp
@@ -215,12 +215,14 @@ class ModuleTimedBans final
: public Module
{
private:
+ ChanModeReference banmode;
CommandTban cmd;
BanWatcher banwatcher;
public:
ModuleTimedBans()
: Module(VF_VENDOR | VF_COMMON, "Adds the /TBAN command which allows channel operators to add bans which will be expired after the specified period.")
+ , banmode(this, "ban")
, cmd(this)
, banwatcher(this)
{
@@ -261,8 +263,8 @@ class ModuleTimedBans final
}
Modes::ChangeList setban;
- setban.push_remove(ServerInstance->Modes.FindMode('b', MODETYPE_CHANNEL), timedban.mask);
- ServerInstance->Modes.Process(ServerInstance->FakeClient, timedban.chan, NULL, setban);
+ setban.push_remove(*banmode, timedban.mask);
+ ServerInstance->Modes.Process(ServerInstance->FakeClient, timedban.chan, nullptr, setban);
}
}
diff --git a/src/modules/m_websocket.cpp b/src/modules/m_websocket.cpp
index d682d77df..5d7b95c36 100644
--- a/src/modules/m_websocket.cpp
+++ b/src/modules/m_websocket.cpp
@@ -386,15 +386,23 @@ class WebSocketHook final
irc::sockets::sockaddrs realsa(luser->client_sa);
HTTPHeaderFinder proxyheader;
- if (proxyheader.Find(recvq, "X-Real-IP:", 10, reqend)
- && irc::sockets::aptosa(proxyheader.ExtractValue(recvq), realsa.port(), realsa))
+ if (proxyheader.Find(recvq, "X-Real-IP:", 10, reqend) || proxyheader.Find(recvq, "X-Forwarded-For:", 16, reqend))
{
- // Nothing to do here.
+ // Attempt to parse the proxy HTTP header.
+ irc::sockets::aptosa(proxyheader.ExtractValue(recvq), realsa.port(), realsa);
}
- else if (proxyheader.Find(recvq, "X-Forwarded-For:", 16, reqend)
- && irc::sockets::aptosa(proxyheader.ExtractValue(recvq), realsa.port(), realsa))
+ else
{
- // Nothing to do here.
+ // The proxy header is missing.
+ FailHandshake(sock, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n", "WebSocket: Received a proxied HTTP request that did not send a real IP address header");
+ return -1;
+ }
+
+ if (realsa.family() == AF_UNSPEC)
+ {
+ // The proxy header value contains a malformed value.
+ FailHandshake(sock, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n", "WebSocket: Received a proxied HTTP request that sent a malformed real IP address");
+ return -1;
}
for (const auto& proxyrange : config.proxyranges)
diff --git a/src/users.cpp b/src/users.cpp
index f96c95a9d..7d91de2b3 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1218,9 +1218,13 @@ const std::string& FakeUser::GetFullRealHost()
ConnectClass::ConnectClass(std::shared_ptr<ConfigTag> tag, char t, const std::vector<std::string>& masks)
: config(tag)
- , type(t)
- , name("unnamed")
, hosts(masks)
+ , name("unnamed")
+ , type(t)
+ , fakelag(true)
+ , maxconnwarn(true)
+ , resolvehostnames(true)
+ , uniqueusername(false)
{
}
@@ -1255,25 +1259,26 @@ ConnectClass::ConnectClass(std::shared_ptr<ConfigTag> tag, char t, const std::ve
void ConnectClass::Update(const std::shared_ptr<ConnectClass> src)
{
+ commandrate = src->commandrate;
config = src->config;
- type = src->type;
fakelag = src->fakelag;
- name = src->name;
- registration_timeout = src->registration_timeout;
- hosts = src->hosts;
- pingtime = src->pingtime;
- softsendqmax = src->softsendqmax;
hardsendqmax = src->hardsendqmax;
- recvqmax = src->recvqmax;
- penaltythreshold = src->penaltythreshold;
- commandrate = src->commandrate;
- maxlocal = src->maxlocal;
- maxglobal = src->maxglobal;
- maxconnwarn = src->maxconnwarn;
- maxchans = src->maxchans;
+ hosts = src->hosts;
limit = src->limit;
- resolvehostnames = src->resolvehostnames;
- ports = src->ports;
+ maxchans = src->maxchans;
+ maxconnwarn = src->maxconnwarn;
+ maxglobal = src->maxglobal;
+ maxlocal = src->maxlocal;
+ name = src->name;
password = src->password;
passwordhash = src->passwordhash;
+ penaltythreshold = src->penaltythreshold;
+ pingtime = src->pingtime;
+ ports = src->ports;
+ recvqmax = src->recvqmax;
+ registration_timeout = src->registration_timeout;
+ resolvehostnames = src->resolvehostnames;
+ softsendqmax = src->softsendqmax;
+ type = src->type;
+ uniqueusername = src->uniqueusername;
}