Skip to content

Commit 252c238

Browse files
committed
Ensure oauth secure cookie expires
If login isn't completed in 10 minutes, expire the cookie and require a start-over.
1 parent eb629db commit 252c238

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pgweb/account/oauthclient.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import json
1111
import os
1212
import sys
13+
import time
1314
import urllib.parse
1415
from Cryptodome import Random
1516
from Cryptodome.Cipher import AES
@@ -38,6 +39,7 @@ def configure():
3839

3940

4041
def set_encrypted_oauth_cookie_on(response, cookiecontent, path=None):
42+
cookiecontent['_ts'] = time.time()
4143
cookiedata = json.dumps(cookiecontent)
4244
r = Random.new()
4345
nonce = r.read(16)
@@ -73,7 +75,13 @@ def get_encrypted_oauth_cookie(request):
7375
base64.urlsafe_b64decode(parts['t'][0]),
7476
)
7577

76-
return json.loads(s)
78+
d = json.loads(s)
79+
if time.time() - d['_ts'] > 10 * 60:
80+
# 10 minutes to complete oauth login
81+
raise OAuthException("Cookie expired")
82+
del d['_ts']
83+
84+
return d
7785

7886

7987
def delete_encrypted_oauth_cookie_on(response):

0 commit comments

Comments
 (0)