Parcourir la source

Merge pull request #207 from pointhi/hash_fix

[fix] hash error if url is including non ascii characters
Adam Tauber il y a 10 ans
Parent
révision
4a20fc202e
1 fichiers modifiés avec 5 ajouts et 3 suppressions
  1. 5
    3
      searx/webapp.py

+ 5
- 3
searx/webapp.py Voir le fichier

215
     if url.startswith('//'):
215
     if url.startswith('//'):
216
         url = 'https:' + url
216
         url = 'https:' + url
217
 
217
 
218
+    url = url.encode('utf-8')
219
+
218
     if not settings['server'].get('image_proxy') and not request.cookies.get('image_proxy'):
220
     if not settings['server'].get('image_proxy') and not request.cookies.get('image_proxy'):
219
         return url
221
         return url
220
 
222
 
221
-    h = hashlib.sha256(url + settings['server']['secret_key']).hexdigest()
223
+    h = hashlib.sha256(url + settings['server']['secret_key'].encode('utf-8')).hexdigest()
222
 
224
 
223
     return '{0}?{1}'.format(url_for('image_proxy'),
225
     return '{0}?{1}'.format(url_for('image_proxy'),
224
                             urlencode(dict(url=url, h=h)))
226
                             urlencode(dict(url=url, h=h)))
553
 
555
 
554
 @app.route('/image_proxy', methods=['GET'])
556
 @app.route('/image_proxy', methods=['GET'])
555
 def image_proxy():
557
 def image_proxy():
556
-    url = request.args.get('url')
558
+    url = request.args.get('url').encode('utf-8')
557
 
559
 
558
     if not url:
560
     if not url:
559
         return '', 400
561
         return '', 400
560
 
562
 
561
-    h = hashlib.sha256(url + settings['server']['secret_key']).hexdigest()
563
+    h = hashlib.sha256(url + settings['server']['secret_key'].encode('utf-8')).hexdigest()
562
 
564
 
563
     if h != request.args.get('h'):
565
     if h != request.args.get('h'):
564
         return '', 400
566
         return '', 400