Skip to content

Backport 239a6b4#14224

Merged
giohappy merged 7 commits into
5.0.xfrom
backport_239a6b4
May 14, 2026
Merged

Backport 239a6b4#14224
giohappy merged 7 commits into
5.0.xfrom
backport_239a6b4

Conversation

@giohappy
Copy link
Copy Markdown
Contributor

No description provided.

@cla-bot cla-bot Bot added the cla-signed CLA Bot: community license agreement signed label May 14, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive file validation framework to enhance security during uploads. It implements a new FileValidationUploadHandler that utilizes libmagic for early content-type sniffing and adds a dedicated ZIP validation utility to protect against path traversal and ZIP bombs. Additionally, the documents API has been hardened by restricting allowed HTTP methods and ensuring that file-related metadata is read-only. Feedback suggests including the files field in the read_only_fields of the DocumentSerializer to fully align with the intended lockdown and adding a null check for file_name in the upload handler to prevent potential TypeError exceptions.

# name and extension determine where the document file lives on disk
# and how it is served. POST/PUT are blocked at the http_method_names
# layer; making them read-only locks them down on PATCH too.
read_only_fields = ("name", "extension")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The PR description states that files is locked down, but it is not included in read_only_fields. If files is a field in the serializer, it remains mutable via PATCH requests. Please add files to read_only_fields to ensure it is locked down as intended.

Suggested change
read_only_fields = ("name", "extension")
read_only_fields = ("name", "extension", "files")

self.magic_mimetype_map = self.validation_config.get("magic_mimetype_map", {})
self.magic_description_map = self.validation_config.get("magic_description_map", {})

self.extension = Path(self.file_name).suffix.replace(".", "").lower()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Accessing self.file_name directly in Path() can raise a TypeError if file_name is None. It is safer to provide a default empty string.

Suggested change
self.extension = Path(self.file_name).suffix.replace(".", "").lower()
self.extension = Path(self.file_name or "").suffix.replace(".", "").lower()

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 95.88336% with 24 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (5.0.x@07fe6a0). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff            @@
##             5.0.x   #14224   +/-   ##
========================================
  Coverage         ?   74.29%           
========================================
  Files            ?      940           
  Lines            ?    56288           
  Branches         ?     7641           
========================================
  Hits             ?    41820           
  Misses           ?    12791           
  Partials         ?     1677           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@giohappy giohappy merged commit 16ec8b3 into 5.0.x May 14, 2026
13 checks passed
@giohappy giohappy deleted the backport_239a6b4 branch May 14, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed CLA Bot: community license agreement signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant