Add file checksum validation

This commit is contained in:
Tiago Garcia 2024-11-20 16:32:50 +00:00
parent 7fd5f1bcd8
commit 07ec667483
Signed by: TiagoRG
GPG Key ID: DFCD48E3F420DB42
2 changed files with 8 additions and 2 deletions

View File

@ -1,4 +1,3 @@
cryptography
flask
flask_sqlalchemy
pytest

View File

@ -83,6 +83,13 @@ def file_upload_content():
if not file:
return jsonify({"error": "Invalid file data"}), 400
file_sum = request.headers.get("File-Checksum")
if not file_sum:
return jsonify({"error": "No file checksum provided"}), 400
if file_sum != utils.get_hash(file.stream):
return jsonify({"error": "File checksum mismatch"}), 400
file = upload_service.write_file(session_token, file.stream)
if isinstance(file, tuple):
return file