Skip to content

Commit 30749b7

Browse files
committed
Revert skipping validation if webhook key not set
1 parent 32e75c1 commit 30749b7

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

anymail/webhooks/mailpace.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,26 @@ def __init__(self, **kwargs):
7575
# MailPace doesn't send a signature for inbound webhooks, yet
7676
# When/if MailPace does this, move this to the parent class
7777
def validate_request(self, request):
78-
if self.webhook_key is None:
79-
return True
80-
else:
81-
try:
82-
signature_base64 = request.headers["X-MailPace-Signature"]
83-
signature = base64.b64decode(signature_base64)
84-
except (KeyError, binascii.Error):
85-
raise AnymailWebhookValidationFailure(
86-
"MailPace webhook called with invalid or missing signature"
87-
)
88-
89-
verify_key_base64 = self.webhook_key
90-
91-
verify_key = VerifyKey(base64.b64decode(verify_key_base64))
92-
93-
message = request.body
94-
95-
try:
96-
verify_key.verify(message, signature)
97-
except (CryptoError, ValueError):
98-
raise AnymailWebhookValidationFailure(
99-
"MailPace webhook called with incorrect signature"
100-
)
78+
try:
79+
signature_base64 = request.headers["X-MailPace-Signature"]
80+
signature = base64.b64decode(signature_base64)
81+
except (KeyError, binascii.Error):
82+
raise AnymailWebhookValidationFailure(
83+
"MailPace webhook called with invalid or missing signature"
84+
)
85+
86+
verify_key_base64 = self.webhook_key
87+
88+
verify_key = VerifyKey(base64.b64decode(verify_key_base64))
89+
90+
message = request.body
91+
92+
try:
93+
verify_key.verify(message, signature)
94+
except (CryptoError, ValueError):
95+
raise AnymailWebhookValidationFailure(
96+
"MailPace webhook called with incorrect signature"
97+
)
10198

10299
def esp_to_anymail_event(self, esp_event):
103100
event_type = self.event_record_types.get(esp_event["event"], EventType.UNKNOWN)

0 commit comments

Comments
 (0)