bfbf2780ee1c — Martin B. 10 years ago
Catch invalid lease_seconds values supplied by GET
1 files changed, 7 insertions(+), 7 deletions(-)

M djpubsubhubbub/views.py
M djpubsubhubbub/views.py +7 -7
@@ 1,6 1,5 @@ 
 import urllib
 import feedparser
-from datetime import datetime
 
 from django.http import HttpResponse, Http404
 from django.shortcuts import get_object_or_404

          
@@ 18,10 17,11 @@ def callback(request, pk):
             mode = request.GET['hub.mode']
             topic = request.GET['hub.topic']
             challenge = request.GET['hub.challenge']
-            lease_seconds = request.GET.get(
-                'hub.lease_seconds',
-                DEFAULT_LEASE_SECONDS,
-            )
+            lease_seconds = request.GET.get('hub.lease_seconds', '')
+            try:
+                lease_seconds = int(lease_seconds)
+            except ValueError:
+                lease_seconds = DEFAULT_LEASE_SECONDS
             verify_token = request.GET.get('hub.verify_token', '')
         except MultiValueDictKeyError:
             # Raise 404 instead of 500 error

          
@@ 53,7 53,7 @@ def callback(request, pk):
 
             subscription.verified = True
             subscription.is_subscribed = True
-            subscription.set_expiration(int(lease_seconds))
+            subscription.set_expiration(lease_seconds)
             verified.send(sender=subscription)
         elif mode == 'unsubscribe':
             if not verify_token.startswith('unsubscribe'):

          
@@ 61,7 61,7 @@ def callback(request, pk):
 
             subscription.verified = False
             subscription.is_subscribed = False
-            subscription.set_expiration(int(lease_seconds))
+            subscription.set_expiration(lease_seconds)
 
         return HttpResponse(challenge, content_type='text/plain')
     elif request.method == 'POST':