Skip to content

Commit

Permalink
Add an option to avoid checking claimed mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMaul committed Jun 24, 2024
1 parent d559ca5 commit 54b3ffb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/matrix_content_scanner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def _parse_size(size: Optional[Union[str, float]]) -> Optional[float]:
"script": {"type": "string"},
"temp_directory": {"type": "string"},
"removal_command": {"type": "string"},
"check_claimed_mimetype": {"type": "boolean"},
"allowed_mimetypes": {"type": "array", "items": {"type": "string"}},
},
},
Expand Down Expand Up @@ -139,6 +140,7 @@ class ScanConfig:
script: str
temp_directory: str
removal_command: str = "rm"
check_claimed_mimetype: bool = True
allowed_mimetypes: Optional[List[str]] = None


Expand Down
4 changes: 3 additions & 1 deletion src/matrix_content_scanner/scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def __init__(self, mcs: "MatrixContentScanner"):

self._max_size_to_cache = mcs.config.result_cache.max_file_size

self._check_claimed_mimetype = mcs.config.scan.check_claimed_mimetype

# List of MIME types we should allow. If None, we don't fail files based on their
# MIME types (besides comparing it with the Content-Type header from the server
# for unencrypted files).
Expand Down Expand Up @@ -526,7 +528,7 @@ def _check_mimetype(
# Check if the MIME type is matching the one that's expected, but only if the file
# is not encrypted (because otherwise we'll always have 'application/octet-stream'
# in the Content-Type header regardless of the actual MIME type of the file).
if encrypted is False and detected_mimetype != claimed_mimetype:
if self._check_claimed_mimetype and encrypted is False and detected_mimetype != claimed_mimetype:
logger.error(
"Mismatching MIME type (%s) and Content-Type header (%s)",
detected_mimetype,
Expand Down

0 comments on commit 54b3ffb

Please sign in to comment.