Skip to content

Commit a1030cc

Browse files
committed
Prevent from spoofing expiration time
1 parent da0f223 commit a1030cc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

webserver/cWebem.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,7 @@ bool cWebemRequestHandler::CheckAuthentication(WebEmSession & session, const req
13001300
int fpos = scookie.find("SID=");
13011301
int upos = scookie.find("_");
13021302
int ppos = scookie.find(".");
1303+
time_t now = mytime(NULL);
13031304
if ((fpos != std::string::npos) && (upos != std::string::npos) && (ppos != std::string::npos))
13041305
{
13051306
sSID = scookie.substr(fpos + 4, upos-fpos-4);
@@ -1311,20 +1312,23 @@ bool cWebemRequestHandler::CheckAuthentication(WebEmSession & session, const req
13111312
sstr << szTime;
13121313
sstr >> stime;
13131314

1314-
time_t now = mytime(NULL);
13151315
expired = stime < now;
13161316
}
13171317

13181318
if (!(sSID.empty() || sAuthToken.empty() || szTime.empty())) {
13191319
std::map<std::string, WebEmSession>::iterator itt = myWebem->m_sessions.find(sSID);
1320+
if (itt != myWebem->m_sessions.end() && (itt->second.expires < now)) {
1321+
// Check if session stored in memory is not expired (prevent from spoofing expiration time)
1322+
expired = true;
1323+
}
13201324
if (expired)
13211325
{
13221326
//timeout, remove session
13231327
m_failcounter = 0;
13241328
send_remove_cookie(rep);
13251329
if (itt != myWebem->m_sessions.end())
13261330
{
1327-
// session exists
1331+
// session exists (delete it from memory and database)
13281332
myWebem->m_sessions.erase(itt);
13291333
rep = reply::stock_reply(reply::unauthorized);
13301334
}

0 commit comments

Comments
 (0)