From 114bb25aa89815675ed3a906247a22ad7a181fc2 Mon Sep 17 00:00:00 2001 From: cflakes Date: Sat, 19 Jun 2010 19:07:24 +0000 Subject: [PATCH] Fixed an issue identified by Un1matr1x: If you were running two 0.090 ZNCs on the same IP, (but different ports), any web login session from ZNC #1 would overwrite the session from ZNC #2. While doing this, also removed an unnecessary check in CHTTPSock::SendCookie and CHTTPSock::GetRequestCookies (which doesn't transparently translate cookie names and has never been used so far). git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2030 726aef4b-f618-498e-8847-2d620e286838 --- HTTPSock.cpp | 10 +--------- HTTPSock.h | 1 - WebModules.cpp | 14 +++++++++----- WebModules.h | 2 +- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/HTTPSock.cpp b/HTTPSock.cpp index 065c6d7e..8e45389d 100644 --- a/HTTPSock.cpp +++ b/HTTPSock.cpp @@ -43,21 +43,13 @@ void CHTTPSock::ReadData(const char* data, size_t len) { bool CHTTPSock::SendCookie(const CString& sKey, const CString& sValue) { if (!sKey.empty() && !sValue.empty()) { - if (m_msRequestCookies.find(sKey) == m_msRequestCookies.end() || - m_msRequestCookies[sKey].StrCmp(sValue) != 0) - { - m_msResponseCookies[sKey] = sValue; - } + m_msResponseCookies[sKey] = sValue; return true; } return false; } -const MCString& CHTTPSock::GetRequestCookies() const { - return m_msRequestCookies; -} - CString CHTTPSock::GetRequestCookie(const CString& sKey) const { MCString::const_iterator it = m_msRequestCookies.find(sKey); diff --git a/HTTPSock.h b/HTTPSock.h index 07641ea9..8ee03632 100644 --- a/HTTPSock.h +++ b/HTTPSock.h @@ -52,7 +52,6 @@ public: void GetPage(); // Cookies - const MCString& GetRequestCookies() const; CString GetRequestCookie(const CString& sKey) const; bool SendCookie(const CString& sKey, const CString& sValue); // Cookies diff --git a/WebModules.cpp b/WebModules.cpp index 029404a5..912d50d7 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -458,25 +458,29 @@ bool CWebSock::ForceLogin() { return false; } -CString CWebSock::GetRequestCookie(const CString& sKey) const { +CString CWebSock::GetRequestCookie(const CString& sKey) { + const CString sPrefixedKey = CString(GetLocalPort()) + "-" + sKey; CString sRet; if (!m_sModName.empty()) { - sRet = CHTTPSock::GetRequestCookie("Mod::" + m_sModName + "::" + sKey); + sRet = CHTTPSock::GetRequestCookie("Mod-" + m_sModName + "-" + sPrefixedKey); } if (sRet.empty()) { - return CHTTPSock::GetRequestCookie(sKey); + return CHTTPSock::GetRequestCookie(sPrefixedKey); } + return sRet; } bool CWebSock::SendCookie(const CString& sKey, const CString& sValue) { + const CString sPrefixedKey = CString(GetLocalPort()) + "-" + sKey; + if (!m_sModName.empty()) { - return CHTTPSock::SendCookie("Mod::" + m_sModName + "::" + sKey, sValue); + return CHTTPSock::SendCookie("Mod-" + m_sModName + "-" + sPrefixedKey, sValue); } - return CHTTPSock::SendCookie(sKey, sValue); + return CHTTPSock::SendCookie(sPrefixedKey, sValue); } void CWebSock::OnPageRequest(const CString& sURI) { diff --git a/WebModules.h b/WebModules.h index 0c8fc5a8..03cb72d6 100644 --- a/WebModules.h +++ b/WebModules.h @@ -154,7 +154,7 @@ public: size_t GetAvailSkins(vector& vRet); CString GetSkinName(); - CString GetRequestCookie(const CString& sKey) const; + CString GetRequestCookie(const CString& sKey); bool SendCookie(const CString& sKey, const CString& sValue); static void FinishUserSessions(const CUser& User) {