aboutsummaryrefslogtreecommitdiff
path: root/src/server/authserver/Server/AuthSession.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-07-16 12:57:03 +0200
committerShauren <shauren.trinity@gmail.com>2025-07-16 12:57:03 +0200
commit7b438d389b56acd22653473ac650e8e5d6eb520f (patch)
treeacdea3dac24774944275d82c996da9cd58b75b81 /src/server/authserver/Server/AuthSession.cpp
parent4fb3bbe71830b2ec53d6fd4e4e4efaada46a362a (diff)
Core/Authserver: Add auth session timeout - socket is closed after 10s of inactivity if not authenticated or after 1 minute if authenticated
Diffstat (limited to 'src/server/authserver/Server/AuthSession.cpp')
-rw-r--r--src/server/authserver/Server/AuthSession.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/server/authserver/Server/AuthSession.cpp b/src/server/authserver/Server/AuthSession.cpp
index 6360ee7d871..d2c110af798 100644
--- a/src/server/authserver/Server/AuthSession.cpp
+++ b/src/server/authserver/Server/AuthSession.cpp
@@ -26,6 +26,7 @@
#include "CryptoRandom.h"
#include "DatabaseEnv.h"
#include "IPLocation.h"
+#include "IoContext.h"
#include "Log.h"
#include "RealmList.h"
#include "SecretMgr.h"
@@ -199,6 +200,7 @@ void AccountInfo::LoadResult(Field* fields)
}
AuthSession::AuthSession(tcp::socket&& socket) : Socket(std::move(socket)),
+ _timeout(*underlying_stream().get_executor().target<boost::asio::io_context::executor_type>()),
_status(STATUS_CHALLENGE), _locale(LOCALE_enUS), _os(0), _build(0), _expversion(0), _timezoneOffset(0min)
{
}
@@ -250,6 +252,7 @@ void AuthSession::CheckIpCallback(PreparedQueryResult result)
}
AsyncRead();
+ SetTimeout();
}
void AuthSession::ReadHandler()
@@ -290,6 +293,7 @@ void AuthSession::ReadHandler()
}
packet.ReadCompleted(size);
+ SetTimeout();
}
AsyncRead();
@@ -898,3 +902,34 @@ bool AuthSession::VerifyVersion(std::span<uint8 const> a, Trinity::Crypto::SHA1:
return versionProof == version.GetDigest();
}
+
+void AuthSession::SetTimeout()
+{
+ _timeout.cancel();
+
+ switch (_status)
+ {
+ case STATUS_AUTHED:
+ case STATUS_WAITING_FOR_REALM_LIST:
+ _timeout.expires_after(1min);
+ break;
+ case STATUS_XFER:
+ return;
+ default:
+ _timeout.expires_after(10s);
+ break;
+ }
+
+ _timeout.async_wait([selfRef = weak_from_this()](boost::system::error_code const& error)
+ {
+ std::shared_ptr<AuthSession> self = selfRef.lock();
+ if (!self)
+ return;
+
+ if (error == boost::asio::error::operation_aborted)
+ return;
+
+ TC_LOG_DEBUG("server.authserver", "{}:{} session timed out.", self->GetRemoteIpAddress().to_string(), self->GetRemotePort());
+ self->CloseSocket();
+ });
+}