summaryrefslogtreecommitdiff
path: root/matweb/frontend.py
diff options
context:
space:
mode:
authorjfriedli2020-04-26 09:50:14 -0700
committerjfriedli2020-04-26 09:50:14 -0700
commitc301e472bd7fd79d675c5df089db0b16fd1e2cfe (patch)
treec3332e0f974edc09881b5534c35becc5b9fffa3b /matweb/frontend.py
parente1bac8b6a7fd857f38b7bcb678398c82baaa8fd5 (diff)
Resolve "Use a HMAC instead of a hash"
Diffstat (limited to 'matweb/frontend.py')
-rw-r--r--matweb/frontend.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/matweb/frontend.py b/matweb/frontend.py
index 93432b4..2e25467 100644
--- a/matweb/frontend.py
+++ b/matweb/frontend.py
@@ -18,8 +18,8 @@ def info():
18 ) 18 )
19 19
20 20
21@routes.route('/download/<string:key>/<string:filename>') 21@routes.route('/download/<string:key>/<string:secret>/<string:filename>')
22def download_file(key: str, filename: str): 22def download_file(key: str, secret: str, filename: str):
23 if filename != secure_filename(filename): 23 if filename != secure_filename(filename):
24 return redirect(url_for('routes.upload_file')) 24 return redirect(url_for('routes.upload_file'))
25 25
@@ -28,7 +28,7 @@ def download_file(key: str, filename: str):
28 28
29 if not os.path.exists(complete_path): 29 if not os.path.exists(complete_path):
30 return redirect(url_for('routes.upload_file')) 30 return redirect(url_for('routes.upload_file'))
31 if hmac.compare_digest(utils.hash_file(complete_path), key) is False: 31 if hmac.compare_digest(utils.hash_file(complete_path, secret), key) is False:
32 return redirect(url_for('routes.upload_file')) 32 return redirect(url_for('routes.upload_file'))
33 33
34 @after_this_request 34 @after_this_request
@@ -67,10 +67,14 @@ def upload_file():
67 flash('Unable to clean %s' % mime) 67 flash('Unable to clean %s' % mime)
68 return redirect(url_for('routes.upload_file')) 68 return redirect(url_for('routes.upload_file'))
69 69
70 key, meta_after, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER']) 70 key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER'])
71 71
72 return render_template( 72 return render_template(
73 'download.html', mimetypes=mime_types, meta=meta, filename=output_filename, meta_after=meta_after, key=key 73 'download.html',
74 mimetypes=mime_types,
75 meta=meta,
76 download_uri=url_for('routes.download_file', key=key, secret=secret, filename=output_filename),
77 meta_after=meta_after,
74 ) 78 )
75 79
76 max_file_size = int(current_app.config['MAX_CONTENT_LENGTH'] / 1024 / 1024) 80 max_file_size = int(current_app.config['MAX_CONTENT_LENGTH'] / 1024 / 1024)