Skip to content

[BUG]: WebhookSignatureValidator.validate raises TypeError for a non-ASCII v1 instead of InvalidWebhookSignatureErrorΒ #160

Open

Description

πŸ“¦ SDK Version

3.6.0 (master 5da68f4)

πŸ–₯️ Environment Details

Python 3.13, any OS.

🌎 Country

Other

πŸ“ Bug Description

validate compares the hashes with hmac.compare_digest(computed, received_hash) on two str values (mercadopago/webhook/validator.py). compare_digest only accepts ASCII strings, so a v1 value with a non-ASCII character raises TypeError: comparing strings with non-ASCII characters is not supported instead of InvalidWebhookSignatureError. Anyone can POST to the webhook URL, so a handler that catches InvalidWebhookSignatureError as in docs/webhooks.md returns a 500 instead of rejecting the request. It still fails closed. The Node SDK had the same problem with a RangeError (#459 there), fixed in its #463.

βœ… Expected Behavior

InvalidWebhookSignatureError with SignatureMismatch, like any other wrong signature.

❌ Actual Behavior

TypeError: comparing strings with non-ASCII characters is not supported.

πŸ”„ Steps To Reproduce

Run the example below.

πŸ’» Code Example

from mercadopago.webhook.validator import WebhookSignatureValidator

WebhookSignatureValidator.validate(
    "ts=1704908010,v1=" + "Γ©" + "a" * 63,
    "req-1",
    "123",
    "test-secret",
)
# TypeError: comparing strings with non-ASCII characters is not supported

A possible fix is to compare bytes (hmac.compare_digest(computed.encode(), received_hash.encode("utf-8"))) or to reject a non-hex v1 before comparing, with a test.

βœ… Checklist

  • I have verified that I am using the latest SDK version
  • I have searched existing issues and this bug has not been reported
  • I have included a minimal code example to reproduce the problem
  • I have removed all sensitive information (tokens, credentials, real data)

Activity

  1. dansonofbass commented on Nov 19, 2026

    @dansonofbass

    Hi! I've completed the fix for this issue and pushed it to my fork.

    The change prevents non-ASCII webhook signatures from raising an unexpected TypeError, while preserving the existing HMAC validation behavior.

    All 205 tests passed locally, along with pylint and isort checks.

    I tried opening a PR, but GitHub says pull requests are restricted to repository collaborators.

    Here's my branch:
    https://github.com/dansonofbass/sdk-python/tree/fix/160-non-ascii-webhook-signature

    Would it be possible to enable PR submissions for external contributors, or is there another preferred way to submit the fix?

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions