safeuploads 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,170 @@
1
+ Metadata-Version: 2.4
2
+ Name: safeuploads
3
+ Version: 0.1.0
4
+ Summary: A comprehensive file security system for validating uploads and preventing attacks
5
+ License: MIT
6
+ License-File: LICENSE.md
7
+ Author: João Vitória Silva
8
+ Author-email: joao@endurain.com
9
+ Requires-Python: >=3.13
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Provides-Extra: dev
15
+ Provides-Extra: fastapi
16
+ Requires-Dist: fastapi (>=0.110,<1.0) ; extra == "fastapi"
17
+ Requires-Dist: pytest (>=8.0,<9.0) ; extra == "dev"
18
+ Requires-Dist: pytest-asyncio (>=0.23,<1.0) ; extra == "dev"
19
+ Requires-Dist: pytest-cov (>=4.1,<5.0) ; extra == "dev"
20
+ Requires-Dist: python-magic (>=0.4.27,<0.5.0)
21
+ Description-Content-Type: text/markdown
22
+
23
+ # safeuploads
24
+
25
+ ![License](https://img.shields.io/github/license/joaovitoriasilva/safeuploads)
26
+ [![GitHub release](https://img.shields.io/github/v/release/joaovitoriasilva/safeuploads)](https://github.com/joaovitoriasilva/safeuploads/releases)
27
+ [![GitHub stars](https://img.shields.io/github/stars/joaovitoriasilva/safeuploads.svg?style=social&label=Star)](https://github.com/joaovitoriasilva/safeuploads/stargazers)
28
+
29
+ Secure file upload validation for Python 3.13+ applications. Catches dangerous filenames, malicious extensions, Windows reserved names, and compression-based attacks before you accept an upload.
30
+
31
+ ## Features
32
+
33
+ - **Framework-agnostic** async validation (FastAPI, generic)
34
+ - Filename sanitization and Unicode security checks
35
+ - Extension validation with configurable allow/block lists
36
+ - ZIP bomb detection and content inspection
37
+ - MIME type verification with signature validation
38
+ - Rich exception hierarchy for precise error handling
39
+ - Zero configuration required—secure defaults out of the box
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install safeuploads
45
+ ```
46
+
47
+ For FastAPI integration:
48
+ ```bash
49
+ pip install safeuploads[fastapi]
50
+ ```
51
+
52
+ ## Quick Start
53
+
54
+ ```python
55
+ from fastapi import FastAPI, UploadFile, HTTPException
56
+ from safeuploads import FileValidator
57
+ from safeuploads.exceptions import FileValidationError
58
+
59
+ app = FastAPI()
60
+ validator = FileValidator()
61
+
62
+ @app.post("/upload")
63
+ async def upload_image(file: UploadFile):
64
+ try:
65
+ await validator.validate_image_file(file)
66
+ except FileValidationError as e:
67
+ raise HTTPException(status_code=400, detail=str(e))
68
+
69
+ return {"status": "success", "filename": file.filename}
70
+ ```
71
+
72
+ ## Configuration
73
+
74
+ ```python
75
+ from safeuploads import FileValidator, FileSecurityConfig
76
+
77
+ # Use default secure configuration
78
+ validator = FileValidator()
79
+
80
+ # Or customize limits
81
+ config = FileSecurityConfig()
82
+ config.limits.max_image_size = 10 * 1024 * 1024 # 10 MiB
83
+ config.limits.max_compression_ratio = 50
84
+
85
+ validator = FileValidator(config=config)
86
+ ```
87
+
88
+ ## Exception Handling
89
+
90
+ ```python
91
+ from safeuploads.exceptions import (
92
+ FileValidationError, # Base exception
93
+ FileSizeError, # File too large
94
+ ExtensionSecurityError, # Dangerous extension
95
+ ZipBombError, # Compression attack
96
+ )
97
+
98
+ try:
99
+ await validator.validate_image_file(file)
100
+ except FileSizeError as err:
101
+ return {"error": "File too large", "max_size": err.max_size}
102
+ except ExtensionSecurityError as err:
103
+ return {"error": "File type not allowed", "extension": err.extension}
104
+ except FileValidationError as err:
105
+ return {"error": str(err), "code": err.error_code}
106
+ ```
107
+
108
+ ## Current Status & Roadmap
109
+
110
+ ### What's Working
111
+
112
+ - **Filename Security**: Unicode normalization, directory traversal prevention, Windows reserved names blocking
113
+ - **Extension Validation**: Allow/block lists with configurable rules, dangerous extension detection
114
+ - **Compression Security**: ZIP bomb detection, nested archive inspection, size and ratio limits
115
+ - **Content Inspection**: Deep ZIP content analysis with configurable depth and entry limits
116
+ - **MIME Type Verification**: Magic number validation for common file types
117
+ - **Rich Exception System**: Machine-readable error codes with detailed context
118
+
119
+ ### Planned Improvements
120
+
121
+ #### Critical (Pre-1.0)
122
+ - **Streaming Validation**: Memory-efficient processing for large files to prevent resource exhaustion
123
+ - **Resource Limits**: CPU and memory monitoring during validation operations
124
+ - **Rate Limiting Guide**: Documentation and examples for production deployments
125
+
126
+ #### High Priority
127
+ - **Enhanced ZIP Security**: Protection against recursive ZIP structures and algorithmic complexity attacks
128
+ - **Audit Logging**: Structured logging for security-relevant events with request correlation
129
+ - **Performance Optimizations**: Pattern caching, compiled regex optimization, async I/O improvements
130
+
131
+ #### Future Enhancements
132
+ - **Additional File Types**: .gpx, .tcx, .fit, .gz
133
+ - **Content Analysis**: Malware signature detection, embedded script scanning
134
+ - **Fuzzing Tests**: Automated testing with malformed and malicious payloads
135
+ - **Security Documentation**: Threat model, architecture diagrams, integration security checklist
136
+
137
+ ### Production Readiness
138
+
139
+ **Status**: Beta - suitable for testing, not yet recommended for production use
140
+
141
+ **Before Production**:
142
+ 1. Address memory exhaustion vulnerability in ZIP inspection
143
+ 2. Implement streaming validation for large files
144
+ 3. Complete security audit and penetration testing
145
+
146
+ **Known Limitations**:
147
+ - No built-in rate limiting (must be implemented at application level)
148
+ - Limited to synchronous content reading in ZIP inspection
149
+ - Performance not yet optimized for high-throughput scenarios
150
+
151
+ ## Documentation
152
+
153
+ Full documentation available at [link to your docs].
154
+
155
+ ## Sponsors
156
+
157
+ A huge thank you to the project sponsors! Your support helps keep this project going.
158
+
159
+ Consider [sponsoring safeuploads on GitHub](https://github.com/sponsors/joaovitoriasilva) to ensure continuous development.
160
+
161
+ ## License
162
+
163
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
164
+
165
+ ## Contributing
166
+
167
+ Contributions welcome! See [Contributing Guidelines](CONTRIBUTING.md) for guidelines.
168
+
169
+
170
+
@@ -0,0 +1,18 @@
1
+ safeuploads/__init__.py,sha256=IjdtiwQwAYYi9bTy3hJ-vfk8hyO_MnCF4M06rLoROUw,2285
2
+ safeuploads/config.py,sha256=YChaxSF6bPkqpWheBRR6dycZ5iicY4WJt9xvHwMKlic,31367
3
+ safeuploads/enums.py,sha256=JstzXMwHJOAPofkApw9B3rym4y2kPWnACVnA_96wJmk,10850
4
+ safeuploads/exceptions.py,sha256=MGlCyEkPKNHz9fozLn8UFCgSJlaxvSOiSpXXPQeRv5M,13902
5
+ safeuploads/file_validator.py,sha256=LUs6JREc0LfuDteQAjm570ET8EiPO0CQLmpKvO23RLg,20178
6
+ safeuploads/inspectors/__init__.py,sha256=_QEFPkjdItLHRs3DdNsUDkhV2KRgb31Alx2s6gIVWRs,287
7
+ safeuploads/inspectors/zip_inspector.py,sha256=DhBcDKgzAhzbY8dfSpxb4Fsymks5jWtTonJhThAOj9o,13596
8
+ safeuploads/protocols.py,sha256=hDH_BxjX6g7PtNwyEF7pOYGKjCX7t5adxAp5InvDqVM,1290
9
+ safeuploads/validators/__init__.py,sha256=0rt8iYrwI7GU1QxmHdNoHfLamDlh81GCgWp3K3akvZ8,705
10
+ safeuploads/validators/base.py,sha256=IWe7WNKvmj5at5LDwz4qCBaorS607hVsn-DoR6ekICM,997
11
+ safeuploads/validators/compression_validator.py,sha256=vWXIIT7ZKxoXCDiOn8skdz4PKvEpBOUeNx4Ban76vCU,12548
12
+ safeuploads/validators/extension_validator.py,sha256=1FVr2vzlbVMf1zCA6j-kh0DxaiwPzp0Gf730wKz3F5Q,3294
13
+ safeuploads/validators/unicode_validator.py,sha256=nuzzw3iZeqSKF8DPiMHPckcLNo4wpj_-0PYO5g0Cd14,4737
14
+ safeuploads/validators/windows_validator.py,sha256=E9roybe445S-LFQtAJuG-faakEUugflJH7vjCN1m620,3107
15
+ safeuploads-0.1.0.dist-info/METADATA,sha256=dZUWCQi9ukqqJ7xI-sDyaaazqJnTj_zfmB8DjFlyC5s,6039
16
+ safeuploads-0.1.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
17
+ safeuploads-0.1.0.dist-info/licenses/LICENSE.md,sha256=3lUa2q_D33W04le3YjeYY5uZ4mwdkzr657SuLKMVJtg,1063
18
+ safeuploads-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.2.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2025 João Vitória Silva
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.