File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616# under the License.
1717
1818import logging
19- from sys import stderr
19+ from sys import stderr , hexversion
2020logging .basicConfig (stream = stderr )
2121
2222import hmac
@@ -75,8 +75,16 @@ def index():
7575
7676 # HMAC requires the key to be bytes, but data is string
7777 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 )
8088
8189 # Implement ping
8290 event = request .headers .get ('X-GitHub-Event' , 'ping' )
You can’t perform that action at this time.
0 commit comments