Skip to content

[BUG]: tolerance_seconds rejects every Orders API notification (ts in milliseconds)Β #159

Open

Description

πŸ“¦ SDK Version

3.6.0 (master 5da68f4)

πŸ–₯️ Environment Details

Python 3.13, any OS. The check is pure Python.

🌎 Country

Other

πŸ“ Bug Description

Since #142, WebhookSignatureValidator.validate treats ts as seconds when tolerance_seconds is set (mercadopago/webhook/validator.py, drift_ms = abs(now() - int(ts) * 1000)). That fixed Payments notifications, where ts has 10 digits (1704908010), but Orders API notifications send a 13 digit timestamp. The Orders notifications page shows x-signature: ts=1742505638683,v1=.... For that value the drift is tens of thousands of years, so every Orders notification with a valid signature is rejected with TimestampOutOfTolerance. docs/webhooks.md recommends tolerance_seconds=300, and the validate docstring itself says ts=<ms>.

The Node SDK has the same code, and the Go SDK has the opposite problem (mercadopago/sdk-go#155).

βœ… Expected Behavior

A valid notification within the tolerance is accepted for both formats: 10 digit seconds (Payments) and 13 digit milliseconds (Orders).

❌ Actual Behavior

InvalidWebhookSignatureError: TimestampOutOfTolerance for every Orders notification when tolerance_seconds is set.

πŸ”„ Steps To Reproduce

Run the example below. It signs an Orders style notification and validates it one second later.

πŸ’» Code Example

import hashlib
import hmac

from mercadopago.webhook.validator import WebhookSignatureValidator

secret = "test-secret"
ts = "1742505638683"  # Orders API format, milliseconds
manifest = f"id:123;request-id:req-1;ts:{ts};"
digest = hmac.new(secret.encode(), manifest.encode(), hashlib.sha256).hexdigest()

WebhookSignatureValidator.validate(
    f"ts={ts},v1={digest}",
    "req-1",
    "123",
    secret,
    tolerance_seconds=300,
    now=lambda: int(ts) + 1000,
)
# InvalidWebhookSignatureError: Invalid webhook signature: TimestampOutOfTolerance

A possible fix is to treat ts as milliseconds when it has 13 or more digits and as seconds otherwise, with a test for each format.

βœ… 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 16, 2026

    @dansonofbass

    Hi! Just a quick update β€” I've completed the fix and pushed it to my fork.

    I reproduced the bug with a failing regression test, fixed the timestamp handling for both Payments and Orders notifications, and verified that all 208 unit tests pass locally.

    However, GitHub says that only repository collaborators can open pull requests, so I'm currently unable to submit the PR.

    Here's the completed change:

    master...dansonofbass:sdk-python:hotfix/159-webhook-timestamp-units

    Would it be possible to enable external contributions or let me know how I should 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