Fix unicode for hashlib operations
authorMagnus Hagander <magnus@hagander.net>
Sat, 19 Jan 2019 19:12:52 +0000 (20:12 +0100)
committerMagnus Hagander <magnus@hagander.net>
Sat, 26 Jan 2019 15:19:26 +0000 (16:19 +0100)
pgweb/misc/views.py
pgweb/util/middleware.py
tools/purgehook/purgehook.py

index a70b7633d3841f766e5969434c0d14c0bd7bfb8b..c8d7e2db97f3dc6d89f2647c5d0ee77d1117d14d 100644 (file)
@@ -21,7 +21,7 @@ from .forms import SubmitBugForm
 def _make_bugs_messageid(bugid):
     return "<{0}-{1}@postgresql.org>".format(
         bugid,
-        hashlib.md5("{0}-{1}".format(os.getpid(), time.time())).hexdigest()[:16],
+        hashlib.md5("{0}-{1}".format(os.getpid(), time.time()).encode('ascii')).hexdigest()[:16],
     )
 
 
index 941de86ea0b7da17882f8d9b6504e168d6c27132..fa7803f75fdc5f51f3d81e5cb1fae02a2ce1be98 100644 (file)
@@ -38,7 +38,7 @@ class PgMiddleware(object):
             response['x-do-esi'] = "1"
             tlist.remove('base/esi.html')
         if tlist:
-            response['xkey'] = ' '.join(["pgwt_{0}".format(hashlib.md5(t).hexdigest()) for t in tlist])
+            response['xkey'] = ' '.join(["pgwt_{0}".format(hashlib.md5(t.encode('ascii')).hexdigest()) for t in tlist])
 
         # Set security headers
         sources = OrderedDict([
index 291fdac0f1bdbdf27a608d6ca778bbb6bfa9e082..a4a6131a56720a5564d68afe795b9a2b149e6a3d 100755 (executable)
@@ -28,7 +28,7 @@ if __name__ == "__main__":
             tmpl = l[len('templates/'):].strip()
             if tmpl not in BANNED_TEMPLATES:
                 curs.execute("SELECT varnish_purge_xkey(%(key)s)", {
-                    'key': 'pgwt_{0}'.format(hashlib.md5(tmpl).hexdigest()),
+                    'key': 'pgwt_{0}'.format(hashlib.md5(tmpl.encode('ascii')).hexdigest()),
                 })
         elif l.startswith('media/'):
             # For media we can't xkey, but the URL is exact so we can