File tree Expand file tree Collapse file tree 1 file changed +2
-6
lines changed Expand file tree Collapse file tree 1 file changed +2
-6
lines changed Original file line number Diff line number Diff line change 11import datetime
22import json
3- import os
43import uuid
54from functools import wraps
65
7- import binascii
86import jwt
97import six
108from flask import request , current_app
9+ from werkzeug .security import safe_str_cmp
1110try :
1211 from flask import _app_ctx_stack as ctx_stack
1312except ImportError : # pragma: no cover
@@ -42,7 +41,6 @@ def get_jwt_claims():
4241 return getattr (ctx_stack .top , 'jwt_user_claims' , {})
4342
4443
45- # TODO set csrf token in jwt when creating tokens (if enabled)
4644def _create_csrf_token ():
4745 return str (uuid .uuid4 ())
4846
@@ -193,11 +191,9 @@ def _decode_jwt_from_cookies(type):
193191 algorithm = get_algorithm ()
194192 token = _decode_jwt (token , secret , algorithm )
195193
196- # TODO use a safe string comparison here, to prevent timing attacks on the
197- # csrf token
198194 if get_cookie_csrf_protect ():
199195 csrf = request .headers .get (csrf_header_key , None )
200- if not csrf or csrf != token ['csrf' ]:
196+ if not csrf or not safe_str_cmp ( csrf , token ['csrf' ]) :
201197 raise NoAuthorizationError ("Missing or invalid csrf double submit header" )
202198
203199 return token
You can’t perform that action at this time.
0 commit comments