From d0ddfb3355d7724379ba9218b29d20434285380c Mon Sep 17 00:00:00 2001 From: chrisr3d Date: Wed, 30 Oct 2019 09:09:55 +0100 Subject: [PATCH] fix: [expansion] Better config field handling for various modules - Testing if config is present before trying to look whithin the config field - The config field should be there when the module is called form MISP, but it is not always the case when the module is queried from somewhere else --- misp_modules/modules/expansion/farsight_passivedns.py | 7 +++---- misp_modules/modules/expansion/macaddress_io.py | 3 +-- misp_modules/modules/expansion/onyphe.py | 2 +- misp_modules/modules/expansion/onyphe_full.py | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/misp_modules/modules/expansion/farsight_passivedns.py b/misp_modules/modules/expansion/farsight_passivedns.py index 7c1aa27..5d32ea8 100755 --- a/misp_modules/modules/expansion/farsight_passivedns.py +++ b/misp_modules/modules/expansion/farsight_passivedns.py @@ -16,10 +16,9 @@ def handler(q=False): if q is False: return False request = json.loads(q) - if (request.get('config')): - if (request['config'].get('apikey') is None): - misperrors['error'] = 'Farsight DNSDB apikey is missing' - return misperrors + if not request.get('config') or not request['config'].get('apikey'): + misperrors['error'] = 'Farsight DNSDB apikey is missing' + return misperrors client = DnsdbClient(server, request['config']['apikey']) if request.get('hostname'): res = lookup_name(client, request['hostname']) diff --git a/misp_modules/modules/expansion/macaddress_io.py b/misp_modules/modules/expansion/macaddress_io.py index e72fa1e..72f950a 100644 --- a/misp_modules/modules/expansion/macaddress_io.py +++ b/misp_modules/modules/expansion/macaddress_io.py @@ -31,9 +31,8 @@ def handler(q=False): else: return False - if request['config'].get('api_key'): + if request.get('config') and request['config'].get('api_key'): api_key = request['config'].get('api_key') - else: misperrors['error'] = 'Authorization required' return misperrors diff --git a/misp_modules/modules/expansion/onyphe.py b/misp_modules/modules/expansion/onyphe.py index aceaf05..d8db477 100644 --- a/misp_modules/modules/expansion/onyphe.py +++ b/misp_modules/modules/expansion/onyphe.py @@ -24,7 +24,7 @@ def handler(q=False): request = json.loads(q) - if not request.get('config') and not (request['config'].get('apikey')): + if not request.get('config') or not request['config'].get('apikey'): misperrors['error'] = 'Onyphe authentication is missing' return misperrors diff --git a/misp_modules/modules/expansion/onyphe_full.py b/misp_modules/modules/expansion/onyphe_full.py index aadb744..3b1c554 100644 --- a/misp_modules/modules/expansion/onyphe_full.py +++ b/misp_modules/modules/expansion/onyphe_full.py @@ -25,7 +25,7 @@ def handler(q=False): request = json.loads(q) - if not request.get('config') and not (request['config'].get('apikey')): + if not request.get('config') or not request['config'].get('apikey'): misperrors['error'] = 'Onyphe authentication is missing' return misperrors