https://postmarkapp.com/developer/webhooks/webhooks-overview
https://<username>:<password>@example.com/webhook
Looking through the Postmark API, there does not seem to be any information about webhook signatures or tokens or hmac for security. The only security mentioned is basic authentication or firewalls.
How do you even set up basic authentication or firewalls to work with Postmark webhooks? Is there anything that needs to be done on nginx or apache?
Basic authentication like this?
requests.post('url',headers=headers,auth=('username','password'), json=json_data)
username:password@mysite.com
To me that does not seem as secure than signature verification. Other APIs like Mailgun have signatures and tokens and hmac for verifying webhooks in the request header.
Mailgun Example:
https://documentation.mailgun.com/en/latest/user_manual.html#webhooks-1
import hashlib, hmac, json
def verify(signing_key, token, timestamp, signature):
hmac_digest = hmac.new(key=signing_key.encode(),
msg=('{}{}'.format(timestamp, token)).encode(),
digestmod=hashlib.sha256).hexdigest()
return hmac.compare_digest(str(signature), str(hmac_digest))
@csrf_exempt
def mailgun_webhook(request):
body_unicode = request.body.decode('utf-8')
body = json.loads(body_unicode)
signature = body['signature']['signature']
token = body['signature']['token']
timestamp = body['signature']['timestamp']
webhook_signing_key = 'KEY'
if verify(webhook_signing_key, token, timestamp, signature) is True:
print('do something')
return HttpResponse(status=200)