-
Notifications
You must be signed in to change notification settings - Fork 12
IVS-605 Run ClamAV and file magic detection to erase potentially harmful content #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
646c638
Run ClamAV and file magic detection to erase potentially harmful content
aothms 68658c2
apt
aothms 134ea88
missing file
aothms ee44823
added missing package
rw-bsi 61a00d6
additional checks when clamscan is not installed
rw-bsi 1f03775
add additonal output
rw-bsi 43b8f0d
include Magic/AV in statistics
rw-bsi f7fd840
show status in Django Admin
rw-bsi 5762895
unit tests + fixes
rw-bsi a205bea
prevent download of malicious file
rw-bsi 95964fe
update submodules
rw-bsi 3054f60
remove duplicate package
rw-bsi f51a00b
fix clamav install in docker
rw-bsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule ifc_gherkin_rules
updated
20 files
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from .. import TaskContext, with_model | ||
| from apps.ifc_validation_models.models import Model | ||
|
|
||
|
|
||
| def process_magic_and_clamav(context:TaskContext): | ||
| output, success, valid = (context.result.get(k) for k in ("output", "success", "valid")) | ||
|
|
||
| with with_model(context.request.id) as model: | ||
| agg_status = Model.Status.VALID if valid else Model.Status.INVALID | ||
| setattr(model, context.config.status_field.name, agg_status) | ||
|
|
||
| model.save(update_fields=[context.config.status_field.name]) | ||
| return f'Magic and av check completed:\nsuccess = {success}\nvalid = {valid}\noutput = {output}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
backend/apps/ifc_validation/tests/tests_magic_clamav_task.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import datetime | ||
|
|
||
| from django.test import TransactionTestCase | ||
| from django.contrib.auth.models import User | ||
|
|
||
| from apps.ifc_validation_models.models import * | ||
| from apps.ifc_validation.tasks.utils import get_absolute_file_path | ||
|
|
||
| from ..tasks import magic_clamav_subtask | ||
|
|
||
| class MagicClamAVTaskTestCase(TransactionTestCase): | ||
|
|
||
| def set_user_context(): | ||
| user = User.objects.create(id=1, username='SYSTEM', is_active=True) | ||
| set_user_context(user) | ||
|
|
||
| def test_magic_clamav_task_detects_valid_ifc_file(self): | ||
|
|
||
| # arrange | ||
| MagicClamAVTaskTestCase.set_user_context() | ||
| request = ValidationRequest.objects.create( | ||
| file_name='valid_file.ifc', | ||
| file='valid_file.ifc', | ||
| size=1 | ||
| ) | ||
| request.mark_as_initiated() | ||
|
|
||
| # act | ||
| task = magic_clamav_subtask( | ||
| prev_result={'is_valid': True, 'reason': 'test'}, | ||
| id=request.id, | ||
| file_name=request.file_name | ||
| ) | ||
| print(task) | ||
|
|
||
| # assert | ||
| model = Model.objects.get(id=request.id) | ||
| self.assertIsNotNone(model) | ||
| self.assertEqual(model.status_magic_clamav, Model.Status.VALID) | ||
|
|
||
| def test_magic_clamav_task_detects_eicar_testfile(self): | ||
|
|
||
| # arrange | ||
| MagicClamAVTaskTestCase.set_user_context() | ||
| request = ValidationRequest.objects.create( | ||
| file_name='eicar_testfile.ifc', | ||
| file='eicar_testfile.ifc', | ||
| size=68 | ||
| ) | ||
| request.mark_as_initiated() | ||
|
|
||
| # make sure the test file contains eicar test string | ||
| file_path = get_absolute_file_path(request.file.name) | ||
| with open(file_path, 'w') as f: | ||
| EICAR_TEST_STRING = 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' | ||
| f.write(EICAR_TEST_STRING) | ||
|
|
||
| # act | ||
| task = magic_clamav_subtask( | ||
| prev_result={'is_valid': True, 'reason': 'test'}, | ||
| id=request.id, | ||
| file_name=request.file_name | ||
| ) | ||
| print(task) | ||
|
|
||
| # assert | ||
| model = Model.objects.get(id=request.id) | ||
| self.assertIsNotNone(model) | ||
| self.assertEqual(model.status_magic_clamav, Model.Status.INVALID) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule ifc_validation_models
updated
2 files
| +23 −0 | migrations/0018_model_status_magic_clamav_alter_validationtask_type.py | |
| +11 −0 | models.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was already to strip the file contents so that downloading is harmless https://github.com/buildingSMART/validate/pull/248/files#diff-5db999c346dafe19127402f8a9220bff8cafead114de27b3e971a88d55e4b0dcR162
But thanks for all the additions to this 👍