Skip to content

Introduce UPLOAD_FILES_WHITELIST#581

Open
MarcelGeo wants to merge 1 commit intomasterfrom
upload-allowed-files
Open

Introduce UPLOAD_FILES_WHITELIST#581
MarcelGeo wants to merge 1 commit intomasterfrom
upload-allowed-files

Conversation

@MarcelGeo
Copy link
Collaborator

  • this file paths will be ignored during files extensions and mime type checks

- this file paths will be ignored during files extensions and mime type checks
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an upload file-path whitelist intended to bypass forbidden extension and MIME type checks for specific, configured paths.

Changes:

  • Introduces Configuration.UPLOAD_FILES_WHITELIST in sync configuration.
  • Adds check_skip_validation() and integrates it into is_supported_extension() and is_supported_type().
  • Adds tests covering whitelist behavior (extension + intended MIME-type skip).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
server/mergin/sync/config.py Adds UPLOAD_FILES_WHITELIST configuration option.
server/mergin/sync/utils.py Implements whitelist check and uses it to bypass extension/MIME validation.
server/mergin/tests/test_utils.py Adds unit tests for whitelist behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"mergin.sync.utils.get_mimetype", return_value="application/x-python-code"
), patch("mergin.sync.utils.Configuration.UPLOAD_FILES_WHITELIST", ALLOWED_FILES):
for file_path in ALLOWED_FILES:
assert is_supported_extension(file_path)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

test_mime_type_validation_skip patches get_mimetype and is meant to verify that MIME type validation is skipped for whitelisted paths, but it currently asserts is_supported_extension(file_path) inside the loop. That doesn't exercise is_supported_type at all, so the test will pass even if MIME skipping is broken. Update the assertions to call is_supported_type(...) for the whitelisted paths (and keep the non-whitelisted negative case).

Suggested change
assert is_supported_extension(file_path)
assert is_supported_type(file_path)

Copilot uses AI. Check for mistakes.
Comment on lines 499 to 534
@@ -515,6 +528,8 @@ def is_supported_extension(filepath) -> bool:

def is_supported_type(filepath) -> bool:
"""Check whether the file mimetype is supported."""
if check_skip_validation(filepath):
return True
mime_type = get_mimetype(filepath)
return mime_type.startswith("image/") or mime_type not in FORBIDDEN_MIME_TYPES
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

check_skip_validation compares the passed-in file_path directly against Configuration.UPLOAD_FILES_WHITELIST, but is_supported_type is called with a filesystem path in the upload flow (e.g., temporary_location in server/mergin/sync/models.py). That means the whitelist will never match and MIME type validation will not actually be skipped for the intended project-relative paths. Consider changing the API so is_supported_type/check_skip_validation can check the original project-relative path (e.g., accept both logical_path and local_path, or have the caller decide whether to skip before calling get_mimetype).

Copilot uses AI. Check for mistakes.
EXCLUDED_CLONE_FILENAMES = config(
"EXCLUDED_CLONE_FILENAMES", default="qgis_cfg.xml", cast=Csv()
)
# files that should be ignored during extension and mime type check
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

Comment grammar/casing: consider using “MIME” and pluralizing “checks” (e.g., “ignored during extension and MIME type checks”) for clarity and consistency.

Suggested change
# files that should be ignored during extension and mime type check
# files that should be ignored during extension and MIME type checks

Copilot uses AI. Check for mistakes.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 22061299119

Details

  • 28 of 29 (96.55%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 94.405%

Changes Missing Coverage Covered Lines Changed/Added Lines %
server/mergin/sync/utils.py 6 7 85.71%
Totals Coverage Status
Change from base Build 21908954703: 0.007%
Covered Lines: 8184
Relevant Lines: 8669

💛 - Coveralls

Copy link
Contributor

@harminius harminius left a comment

Choose a reason for hiding this comment

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

Clean and concise. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants