From d5239191fed304b50d6bab0a01f8556a33fde19d Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 7 Aug 2018 14:19:46 -0400 Subject: [PATCH] Fixes #2320: TypeError when dispatching a webhook with a secret key configured --- netbox/extras/webhooks_worker.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/netbox/extras/webhooks_worker.py b/netbox/extras/webhooks_worker.py index 91e95baa1..2122d1154 100644 --- a/netbox/extras/webhooks_worker.py +++ b/netbox/extras/webhooks_worker.py @@ -37,8 +37,12 @@ def process_webhook(webhook, data, model_class, event, timestamp): prepared_request = requests.Request(**params).prepare() if webhook.secret != '': - # sign the request with the secret - hmac_prep = hmac.new(bytearray(webhook.secret, 'utf8'), prepared_request.body, digestmod=hashlib.sha512) + # Sign the request with a hash of the secret key and its content. + hmac_prep = hmac.new( + key=webhook.secret.encode('utf8'), + msg=prepared_request.body.encode('utf8'), + digestmod=hashlib.sha512 + ) prepared_request.headers['X-Hook-Signature'] = hmac_prep.hexdigest() with requests.Session() as session: