From d7848702097ca6a3e8630ca6d46210abf7314673 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Tue, 28 Dec 2021 08:36:31 +0100 Subject: [fix] use hmac.compare_digest instead of == see https://docs.python.org/3/library/hmac.html#hmac.HMAC.hexdigest --- searx/webapp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index a7812f181..788e0d24f 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -1067,8 +1067,9 @@ def image_proxy(): if not url: return '', 400 - h = new_hmac(settings['server']['secret_key'], url.encode()) - if h != request.args.get('h'): + h_url = new_hmac(settings['server']['secret_key'], url.encode()) + h_args = request.args.get('h') + if len(h_url) != len(h_args) or not hmac.compare_digest(h_url, h_args): return '', 400 maximum_size = 5 * 1024 * 1024 -- cgit v1.2.3 From 8f3a7feb47a84344a190ce83e629afde1181f6ae Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 28 Dec 2021 13:44:28 +0100 Subject: [mod] implement is_hmac_of() in webutils / close to new_hmac() Signed-off-by: Markus Heiser , Alexandre Flament --- searx/webapp.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 788e0d24f..a2aa84d9d 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -71,6 +71,7 @@ from searx.webutils import ( get_themes, prettify_url, new_hmac, + is_hmac_of, is_flask_run_cmdline, ) from searx.webadapter import ( @@ -1067,9 +1068,7 @@ def image_proxy(): if not url: return '', 400 - h_url = new_hmac(settings['server']['secret_key'], url.encode()) - h_args = request.args.get('h') - if len(h_url) != len(h_args) or not hmac.compare_digest(h_url, h_args): + if not is_hmac_of(settings['server']['secret_key'], url.encode(), request.args.get('h', '')): return '', 400 maximum_size = 5 * 1024 * 1024 -- cgit v1.2.3