Backport 14267 to 5.1.x#14269
Conversation
There was a problem hiding this comment.
Code Review
This pull request integrates ZIP safety validation into the document upload form to protect against path-traversal, symlinks, and zip bombs, while expanding the covered file extensions to include Office Open XML and OpenDocument formats. It also allows configuring the default maximum upload size via environment variables, updates several project dependencies, and bumps the Nginx image version in the docker-compose configurations. The review feedback recommends seeking the file stream to the beginning before validation to ensure complete data is read.
I am having trouble creating individual review comments. Click here to see my feedback.
geonode/documents/forms.py (149-152)
To ensure defensive programming and robust validation, it is highly recommended to seek the doc_file to the beginning (0) before passing it to validate_safe_zip. If the file stream has been partially or fully read by any previous handlers, validators, or middleware, the ZIP validation might fail or receive incomplete data. Seeking to 0 beforehand prevents this potential issue.
if doc_file and is_zip_extension(doc_file.name):
if hasattr(doc_file, "seek"):
try:
doc_file.seek(0)
except (OSError, ValueError):
pass
source = doc_file.temporary_file_path() if hasattr(doc_file, "temporary_file_path") else doc_file
try:
validate_safe_zip(source)
Checklist
For all pull requests:
The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):
Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.