Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flagsmith/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ def verify_signature(
:param shared_secret: The shared secret configured for this specific webhook.
:return: True if the signature is valid, False otherwise.
"""
if not received_signature.isascii():
return False

expected_signature = generate_signature(request_body, shared_secret)
return hmac.compare_digest(expected_signature, received_signature)
8 changes: 8 additions & 0 deletions tests/test_webhooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

import pytest

from flagsmith.webhooks import generate_signature, verify_signature


Expand Down Expand Up @@ -48,3 +50,9 @@ def test_verify_signature_invalid() -> None:
received_signature="bad",
shared_secret="?",
)


@pytest.mark.parametrize("signature", ["é", "🔒", "a" * 63 + "é", "\ud800"])
@pytest.mark.parametrize("body", ["{}", b"{}"])
def test_verify_signature_rejects_non_ascii(signature: str, body: str | bytes) -> None:
assert verify_signature(body, signature, "secret") is False