Skip to content

Commit 846685c

Browse files
committed
Merge pull request #3 from yscumc/master
Middleware polishing.
2 parents 9e73568 + 3285bc8 commit 846685c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

session_security/middleware.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from django import http
1616
from django.contrib.auth import logout
17+
from django.core.urlresolvers import reverse
1718

1819
from settings import *
1920

@@ -48,8 +49,17 @@ def update_last_activity(self, request, now):
4849
last_activity = request.session['_session_security']
4950
server_idle_for = (now - last_activity).seconds
5051

51-
if 'idleFor' in request.GET:
52-
client_idle_for = int(request.GET['idleFor'])
52+
if (request.path == reverse('session_security_ping') and
53+
'idleFor' in request.GET):
54+
# Gracefully ignore non-integer values
55+
try:
56+
client_idle_for = int(request.GET['idleFor'])
57+
except ValueError:
58+
return
59+
60+
# Disallow negative values, causes problems with delta calculation
61+
if client_idle_for < 0:
62+
client_idle_for = 0
5363

5464
if client_idle_for < server_idle_for:
5565
# Client has more recent activity than we have in the session

0 commit comments

Comments
 (0)