@@ -54,9 +54,9 @@ files with the mime type ``image/svg+xml``. Those files are dangerous since
5454they are executed by a browser without any warnings.
5555
5656Validation hooks do not restrict the upload of other executable files
57- (like ``*.exe `` or shell scripts). Those are not automatically executed
57+ (like ``*.exe `` or shell scripts). ** Those are not automatically executed
5858by the browser but still present a point of attack, if a user saves them
59- to disk and executes them locally.
59+ to disk and executes them locally. **
6060
6161You can release validation restrictions by setting
6262``FILER_REMOVE_FILE_VALIDATORS `` to a list of mime types to be removed from
@@ -111,7 +111,7 @@ This just rejects any file for upload. By default this happens for HTML files
111111
112112 This validator rejects any SVG file that contains the bytes ``<script `` or
113113``javascript: ``. This probably is a too strict criteria, since those bytes
114- might be part of a legitimate say string. The above code is a simplification
114+ might be part of a legitimate string. The above code is a simplification
115115the actual code also checks for occurrences of event attribute like
116116``onclick="..." ``.
117117
@@ -144,10 +144,11 @@ a malicious file unknowingly.
144144 FILER_REMOVE_FILE_VALIDATORS = [
145145 " text/html" ,
146146 " image/svg+xml" ,
147+ " application/octet-stream" ,
147148 ]
148149
149- No HTML upload and restricted SVG upload
150- ........................................
150+ No HTML upload and restricted SVG upload, no binary or unknown file upload
151+ ...........................................................................
151152
152153This is the default setting. It will deny any SVG file that might contain
153154Javascript. It is prone to false positives (i.e. files being rejected that
@@ -176,6 +177,8 @@ in the user's browser.
176177 " image/svg+xml" : [" filer.validation.deny" ],
177178 }
178179
180+ (Still not binary or unknown file upload)
181+
179182Experimental SVG sanitization
180183.............................
181184
@@ -259,3 +262,37 @@ You can use it to distinguish validation for certain user groups if needed.
259262
260263If you distinguish validation by the mime type, remember to register the
261264validator function for all relevant mime types.
265+
266+
267+ Checking uploads for viruses using ClamAV
268+ -----------------------------------------
269+
270+ If you have ClamAV installed an use `django-clamd <https://github.com/vstoykov/django-clamd >`_
271+ you can add a validator that checks for viruses in uploaded files.
272+
273+ .. code-block :: python
274+
275+ FILER_ADD_FILE_VALIDATORS = {
276+ " application/octet-stream" : [" my_validator_app.validators.validate_octet_stream" ],
277+ }
278+
279+
280+ .. code-block :: python
281+
282+ def validate_octet_stream (file_name : str , file : typing.IO , owner : User, mime_type : str ) -> None :
283+ """ Octet streams are binary files without a specific mime type. They are run through
284+ a virus check."""
285+ try :
286+ from django_clamd.validators import validate_file_infection
287+
288+ validate_file_infection(file )
289+ except (ModuleNotFoundError , ImportError ):
290+ raise FileValidationError(
291+ _(' File "{file_name} ": Virus check for binary/unknown file not available' ).format(file_name = file_name)
292+ )
293+
294+ .. note ::
295+
296+ Virus-checked files still might contain executable code. While the code is not
297+ executed by the browser, a user might still download the file and execute it
298+ manually.
0 commit comments