Mercado Libre webhooks: a notice is not an order

visibility202 Views Posted By: & Claude Code list In: ASDD

How does a webhook work?

Mercado Libre sends a request to an address of yours every time something changes: an order, a shipment, a payment, a listing. The notice carries a topic (orders_v2, items…), the path of the resource (/orders/123…) and the identifiers of your application and your account. With that, your system queries the API and gets the real data.

The problem: that address is public

Your webhook address has to be open to the internet, because Mercado Libre must be able to call it. That means anyone else can call it too. And the two pieces of data many systems use to decide "this notice is legitimate" (the application identifier and your account identifier) are not secrets: they travel in every notice, and the application identifier appears in the authorization address that anyone connecting your app can see. The official documentation we reviewed explains how to acknowledge receipt and query the resource, but it does not describe any signature on the notice to verify where it came from. (Mercado Pago notifications do carry an x-signature; that is a different channel.)

Practical conclusion: treat every notice as if it could come from an attacker. A notice is a hint that says "look at this resource", not an order or a source of data.

The flaw we found

Our test stored every notice exactly as it arrived. Later, a process read the invoice notices and built the address to query like this:

https://api.mercadolibre.com + (the text of the notice's "resource" field)

It looks harmless, but that text is written by whoever sends the notice. If the text starts with @ and a domain, the resulting address points to another server, because in a URL whatever comes before @ is interpreted as a user, not as a server. The request went out with your access token in the header, to the attacker's server. We reproduced it locally with a test server: the token arrived.

To exploit it, an attacker had to send a fake notice with the two (non-secret) identifiers and wait for the invoice process to run. We reviewed all stored notices and saw none that looked abnormal. We fixed it anyway.

How to fix it (and what to check in your integration)

  1. Don't build addresses from text in the notice. Extract only the identifier, require it to be numeric (or to match the exact format you expect) and build the path yourself.
  2. Pin the server. Configure the HTTP client with the API's base address and don't let a path change it.
  3. Don't follow redirects on requests that carry your token.
  4. Don't trust the content. After the notice, query the API with your token and use that response. A fake notice should not be able to inject data into your system.
  5. Validate the shape of the notice: topic and resource with reasonable characters and length; reject the rest.
  6. Limit the body size (a few KB is enough) and the number of requests per origin. Without limits, anyone can fill up your database.
  7. Watch out for proxies. If your application sits behind a load balancer or proxy, check that it sees the client's real IP. If it always sees the proxy's, your per-IP limits either don't work or punish everyone equally.
  8. Don't store or log more than necessary, and define how long you keep notices. A table that only grows is a problem waiting to happen.
  9. If the notice is your only source of truth, you will lose data. Notices may never arrive. Schedule a daily check (for example, the orders of the last 48 hours) that compares what you have with what the API says, and measure how many orders it found that no notice announced.

If you use an external service

Ask your provider, in writing:

  • How does it validate that a notice comes from Mercado Libre?
  • Does it build any query from text that arrives in the notice? With what validation?
  • How long does it keep notices, and what data of yours do they contain?
  • What happens if a notice doesn't arrive? Is there a periodic check?
  • Where does it store your token, and which servers can it be sent to?

If your provider doesn't answer clearly, that is useful information.

What did we learn from this webhook test?

A notice is a hint, not an instruction. Anything that depends on the text of a notice being honest (a URL, a path, an unvalidated identifier) is an entry point. The cheapest defense is also the simplest: validate what you accept, pin where you go, and read the source of truth again.

Sources:

https://developers.mercadolibre.com.ar/es_ar/productos-recibe-notificaciones

https://www.mercadopago.com.ar/developers/es/docs/checkout-pro-preferences/payment-notifications

Leave a comment

Please note, comments must be approved before they are published
Sunday Monday Tuesday Wednesday Thursday Friday Saturday January February March April May June July August September October November December