File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 16
16
# under the License.
17
17
18
18
import logging
19
- from sys import stderr
19
+ from sys import stderr , hexversion
20
20
logging .basicConfig (stream = stderr )
21
21
22
22
import hmac
@@ -75,8 +75,16 @@ def index():
75
75
76
76
# HMAC requires the key to be bytes, but data is string
77
77
mac = hmac .new (str (secret ), msg = request .data , digestmod = sha1 )
78
- if not hmac .compare_digest (str (mac .hexdigest ()), str (signature )):
79
- abort (403 )
78
+
79
+ # Python prior to 2.7.7 does not have hmac.compare_digest
80
+ if hexversion >= 0x020707F0 :
81
+ if not hmac .compare_digest (str (mac .hexdigest ()), str (signature )):
82
+ abort (403 )
83
+ else :
84
+ # What compare_digest provides is protection against timing attacks; we
85
+ # can live without this protection for a web-based application
86
+ if not str (mac .hexdigest ()) == str (signature ):
87
+ abort (403 )
80
88
81
89
# Implement ping
82
90
event = request .headers .get ('X-GitHub-Event' , 'ping' )
You can’t perform that action at this time.
0 commit comments