diff --git a/monkey/monkey_island/cc/resources/monkey_configuration.py b/monkey/monkey_island/cc/resources/monkey_configuration.py index 6dab8dddb..7032ba643 100644 --- a/monkey/monkey_island/cc/resources/monkey_configuration.py +++ b/monkey/monkey_island/cc/resources/monkey_configuration.py @@ -1,7 +1,7 @@ import json import flask_restful -from flask import request, jsonify +from flask import request, jsonify, abort from cc.auth import jwt_required from cc.services.config import ConfigService @@ -20,5 +20,6 @@ class MonkeyConfiguration(flask_restful.Resource): if 'reset' in config_json: ConfigService.reset_config() else: - ConfigService.update_config(config_json, should_encrypt=True) + if not ConfigService.update_config(config_json, should_encrypt=True): + abort(400) return self.get() diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index c34db0eac..64b359f61 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -977,9 +977,14 @@ class ConfigService: @staticmethod def update_config(config_json, should_encrypt): if should_encrypt: - ConfigService.encrypt_config(config_json) + try: + ConfigService.encrypt_config(config_json) + except KeyError as e: + logger.error('Bad configuration file was submitted.') + return False mongo.db.config.update({'name': 'newconfig'}, {"$set": config_json}, upsert=True) logger.info('monkey config was updated') + return True @staticmethod def init_default_config(): diff --git a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index afa42d6e7..a97447df0 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -50,6 +50,13 @@ class ConfigurePageComponent extends AuthComponent { headers: {'Content-Type': 'application/json'}, body: JSON.stringify(this.state.configuration) }) + .then(res => { + if (!res.ok) + { + throw Error() + } + return res; + }) .then(res => res.json()) .then(res => { this.setState({ @@ -58,6 +65,9 @@ class ConfigurePageComponent extends AuthComponent { configuration: res.configuration }); this.props.onStatusChange(); + }).catch(error => { + console.log('bad configuration'); + this.setState({lastAction: 'invalid_configuration'}); }); }; @@ -217,6 +227,12 @@ class ConfigurePageComponent extends AuthComponent { Failed importing configuration. Invalid config file. : ''} + { this.state.lastAction === 'invalid_configuration' ? +
+ + An invalid configuration file was imported and submitted, probably outdated. +
+ : ''} { this.state.lastAction === 'import_success' ?