@@ -54,9 +54,9 @@ files with the mime type ``image/svg+xml``. Those files are dangerous since
54
54
they are executed by a browser without any warnings.
55
55
56
56
Validation 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
58
58
by 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. **
60
60
61
61
You can release validation restrictions by setting
62
62
``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
111
111
112
112
This validator rejects any SVG file that contains the bytes ``<script `` or
113
113
``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
115
115
the actual code also checks for occurrences of event attribute like
116
116
``onclick="..." ``.
117
117
@@ -144,10 +144,11 @@ a malicious file unknowingly.
144
144
FILER_REMOVE_FILE_VALIDATORS = [
145
145
" text/html" ,
146
146
" image/svg+xml" ,
147
+ " application/octet-stream" ,
147
148
]
148
149
149
- No HTML upload and restricted SVG upload
150
- ........................................
150
+ No HTML upload and restricted SVG upload, no binary or unknown file upload
151
+ ...........................................................................
151
152
152
153
This is the default setting. It will deny any SVG file that might contain
153
154
Javascript. It is prone to false positives (i.e. files being rejected that
@@ -176,6 +177,8 @@ in the user's browser.
176
177
" image/svg+xml" : [" filer.validation.deny" ],
177
178
}
178
179
180
+ (Still not binary or unknown file upload)
181
+
179
182
Experimental SVG sanitization
180
183
.............................
181
184
@@ -259,3 +262,38 @@ You can use it to distinguish validation for certain user groups if needed.
259
262
260
263
If you distinguish validation by the mime type, remember to register the
261
264
validator function for all relevant mime types.
265
+
266
+
267
+ Checking uploads for viruses using ClamAV
268
+ -----------------------------------------
269
+
270
+ If you have ClamAV installed and 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_REMOVE_FILE_VALIDATORS = [" application/octet-stream" ]
276
+ FILER_ADD_FILE_VALIDATORS = {
277
+ " application/octet-stream" : [" my_validator_app.validators.validate_octet_stream" ],
278
+ }
279
+
280
+
281
+ .. code-block :: python
282
+
283
+ def validate_octet_stream (file_name : str , file : typing.IO , owner : User, mime_type : str ) -> None :
284
+ """ Octet streams are binary files without a specific mime type. They are run through
285
+ a virus check."""
286
+ try :
287
+ from django_clamd.validators import validate_file_infection
288
+
289
+ validate_file_infection(file )
290
+ except (ModuleNotFoundError , ImportError ):
291
+ raise FileValidationError(
292
+ _(' File "{file_name} ": Virus check for binary/unknown file not available' ).format(file_name = file_name)
293
+ )
294
+
295
+ .. note ::
296
+
297
+ Virus-checked files still might contain executable code. While the code is not
298
+ executed by the browser, a user might still download the file and execute it
299
+ manually.
0 commit comments