Replace non-ascii chars in template names when building xkey
authorMagnus Hagander <magnus@hagander.net>
Wed, 18 Nov 2020 10:28:40 +0000 (11:28 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 18 Nov 2020 10:28:40 +0000 (11:28 +0100)
We don't have non-ascii characters in any of our correct URLs, but
people can still specify them on the URL. In this case the xkey isn't
going to match anything anyway, so it is not critical how we handle it,
especially since the generated page is going to be a 404 anyway. So just
use the simple built-in replace function.

pgweb/util/middleware.py

index e16796fd6496fa9b2d9f437cb8342189b70e4c22..acbb7f3f64fb1f4ae9ed65c1ed3d629490175576 100644 (file)
@@ -40,7 +40,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.encode('ascii')).hexdigest()) for t in tlist])
+            response['xkey'] = ' '.join(["pgwt_{0}".format(hashlib.md5(t.encode('ascii', errors='replace')).hexdigest()) for t in tlist])
 
         # Set security headers
         sources = OrderedDict([