safeuploads 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: safeuploads
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A comprehensive file security system for validating uploads and preventing attacks
5
5
  License: MIT
6
6
  License-File: LICENSE.md
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "safeuploads"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "A comprehensive file security system for validating uploads and preventing attacks"
5
5
  authors = [
6
6
  {name = "João Vitória Silva",email = "joao@endurain.com"}
@@ -57,6 +57,7 @@ class SecurityLimits:
57
57
  max_zip_depth: int = 10 # Maximum nesting depth for directories in ZIP
58
58
  max_filename_length: int = 255 # Maximum length for individual file names
59
59
  max_path_length: int = 1024 # Maximum length for full file paths
60
+ max_number_files_same_type: int = 1000 # Maximum number of files of the same type
60
61
  allow_nested_archives: bool = False # Whether to allow nested archive files
61
62
  allow_symlinks: bool = False # Whether to allow symbolic links in ZIP
62
63
  allow_absolute_paths: bool = False # Whether to allow absolute paths in ZIP
@@ -3,6 +3,18 @@
3
3
  from enum import Enum
4
4
 
5
5
 
6
+ class BinaryFileCategory(Enum):
7
+ """
8
+ Enumeration of binary file categories.
9
+
10
+ Attributes:
11
+ FITNESS_FILES: Set of file extensions representing fitness or activity binary files (e.g., '.fit').
12
+ """
13
+
14
+ # Fitness/activity binary files
15
+ FITNESS_FILES = {".fit"}
16
+
17
+
6
18
  class DangerousExtensionCategory(Enum):
7
19
  """
8
20
  File extension categories considered potentially dangerous for uploads.
@@ -9,7 +9,7 @@ import zipfile
9
9
  from typing import TYPE_CHECKING
10
10
 
11
11
  import logging
12
- from ..enums import SuspiciousFilePattern, ZipThreatCategory
12
+ from ..enums import SuspiciousFilePattern, ZipThreatCategory, BinaryFileCategory
13
13
  from ..exceptions import ZipContentError, FileProcessingError, ErrorCode
14
14
 
15
15
  if TYPE_CHECKING:
@@ -220,8 +220,10 @@ class ZipContentInspector:
220
220
 
221
221
  # Check for excessive number of same-type files (potential spam/bomb)
222
222
  for ext, count in file_types.items():
223
- if count > 1000: # More than 1000 files of same type
224
- threats.append(f"Excessive number of {ext} files: {count}")
223
+ if count > self.config.limits.max_number_files_same_type:
224
+ threats.append(
225
+ f"Excessive number of {ext} files: {self.config.limits.max_number_files_same_type}"
226
+ )
225
227
 
226
228
  return threats
227
229
 
@@ -355,9 +357,15 @@ class ZipContentInspector:
355
357
  )
356
358
  break
357
359
 
358
- # Check for script content patterns
359
- if self._contains_script_patterns(content_sample, entry.filename):
360
- threats.append(f"Script content detected in '{entry.filename}'")
360
+ binary_exts = set()
361
+ for category in BinaryFileCategory:
362
+ binary_exts.update(category.value)
363
+
364
+ ext = os.path.splitext(entry.filename)[1].lower()
365
+ if ext not in binary_exts:
366
+ # Check for script content patterns
367
+ if self._contains_script_patterns(content_sample, entry.filename):
368
+ threats.append(f"Script content detected in '{entry.filename}'")
361
369
 
362
370
  except Exception as err:
363
371
  logger.warning(
File without changes
File without changes