Skip to content
IDOR Write-up Intermediate

PayPal IDOR via billing Agreement Token (closed Informative, payment fraud)

An endpoint on Braintree's payment API accepted requests without merchant authentication, so anyone holding a PayPal billing agreement token could generate a payment method nonce for that user. The author claims this exposed the victim's billing address and email and could allow payments to be made from the victim's PayPal account.

Souhaib Naceri Follow

Published on medium.com

Hello everyone, in this article I will show you an Insecure direct object references (IDOR) that I found on PayPal 7 months Ago where an attacker can expose PayPal users data: billing address,email, nonce code using billing Agreement Token.

h4x0r_dz, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Braintree is a PayPal-owned payment gateway. Merchants integrate with it through api.braintreegateway.com, and one of the building blocks of that integration is the payment method nonce: a secure, one-time-use reference to payment information that lets a merchant's server talk to Braintree without ever handling raw card or PayPal data. The report quotes the vendor documentation for this:

A payment method nonce is a secure, one-time-use reference to payment information. It’s the key element that allows your server to communicate sensitive payment information to Braintree without ever touching the raw data.

For PayPal payments, the nonce is derived from a billingAgreementToken, a value that PayPal passes around during the checkout flow. The endpoint that turns a billingAgreementToken into a payment method nonce is:

Text
api.braintreegateway.com/merchants/<ID>/client_api/v1/payment_methods/paypal_accounts

The researcher's argument is that this endpoint should be authenticated by the merchant, because it is the merchant's server that is supposed to exchange the token for a nonce. Instead, the researcher found that a user (or anyone) can send POST requests to it directly and generate payment method nonces.

Setup

The work was done against a real merchant that uses Braintree: Grammarly. The researcher reproduced the issue against Grammarly, opening the victim's PayPal account and repeating the same checkout steps. The merchant identifier used throughout is Grammarly's public client ID, 68r2vzdxyjwst8d7, which the report notes explicitly is public.

The precondition for the attack is possession of a valid billingAgreementToken belonging to another user. The report spends a section on how such tokens can be obtained, so that precondition is not as strong as it sounds.

Finding it

While reading the Braintree documentation on payment method nonces, the researcher reasoned that if a valid billingAgreementToken of another user could be obtained, it would be possible to generate a new nonce and then make a payment. The question was whether the nonce-generation endpoint enforced any authentication of its own. It did not: the endpoint accepts POST requests from the user directly, so a token is enough.

Exploitation

Step 1: start a PayPal checkout at the merchant

  1. Go to https://www.grammarly.com/upgrade and log in with your account.
  2. Choose your plan and select PayPal as the payment method, with an intercepting proxy in place.
  3. Click on PayPal checkout and accept the payment.
  4. When the request below appears, drop it, which cancels the payment.
HTTP
POST /api/v1/subscribe HTTP/1.1Host: subscription.grammarly.comConnection: closeContent-Length: 135Cookie: <>nonce=<nonce>&planId=1005&sessionId=<sessionId>&isTaxable=false&billingCountryCode=US

This shows that Grammarly's own subscription endpoint consumes a payment method nonce (nonce=<nonce>), which is the value the attack will forge.

Step 2: locate the nonce-generation request

Back in the proxy history, find this endpoint and send it to the repeater:

Text
https://api.braintreegateway.com/merchants/68r2vzdxyjwst8d7/client_api/v1/payment_methods/paypal_accounts

Step 3: obtain the victim's token

Open the victim's PayPal account and repeat the same checkout steps, then copy the billingAgreementToken from the victim's flow.

Step 4: swap the token

Change the billingAgreementToken in the request to api.braintreegateway.com/merchants/68r2vzdxyjwst8d7/client_api/v1/payment_methods/paypal_accounts to the victim's token. The report notes again that 68r2vzdxyjwst8d7 is Grammarly's public client ID.

From the original on medium.com

The response contains nonces generated from the victim's billingAgreementToken, and no specific authentication is needed to get them.

Step 5: obtaining tokens for other users

The researcher then addresses the obvious objection: where does an attacker get a valid billingAgreementToken? The report lists several sources.

Wayback Machine

Tools such as waybackurls and gau fetch known URLs for a domain from the Wayback Machine and other archives. The command used was:

Bash
gau paypal.com | grep "ba_token"
From the original on medium.com

The result is a large number of leaked billingAgreementToken values in the Wayback Machine, which the researcher attributes to the token being a public token. The attacker's next step is to find a merchant that will accept one of those tokens: if a token was used at Grammarly, the attacker sends the POST request to the Grammarly merchant endpoint and receives the user's PayPal information. This requires finding the right merchant ID and testing the tokens against it, which the researcher considers feasible given how many companies use the Braintree gateway.

Google dorking

Because the billingAgreementToken is passed in a GET request, some of them can be found on Google with a dork. The researcher notes there is not much there.

From the original on medium.com

Leakage to third parties

The researcher also found the billingAgreementToken leaked to third parties, for example Google Analytics.

From the original on medium.com

Root cause

Missing authentication on a sensitive endpoint. The endpoint api.braintreegateway.com/merchants/<ID>/client_api/v1/payment_methods/paypal_accounts is meant to be called by the merchant, but it accepts requests from the user and generates payment method nonces from whatever billingAgreementToken is supplied. The researcher's view is that the only parties who should have access are merchants using their API keys, since api.braintreegateway.com has many authentication endpoints and this one should behave the same way. The researcher's view is that the endpoint should require merchant authentication, as other endpoints on api.braintreegateway.com do.

Impact

An attacker who holds a valid billingAgreementToken can expose PayPal user data: billing address, email and nonce code. Because the same endpoint generates a valid nonce that can be used to make a payment to the merchant, an attacker can make payments from PayPal victims' accounts. The report notes the attacker needs to find the right merchant ID and test the tokens against it.

Fix

The report does not say what was changed. The researcher's recommendation is that the endpoint must be authenticated, with access limited to merchants using their API keys, consistent with the other authentication endpoints on api.braintreegateway.com.

  1. Other Braintree client endpoints. Enumerate client_api paths under a merchant ID and replay them without merchant credentials. A positive result is a response containing payment method data or a nonce for a token you supplied.
  2. Token sources. Run gau <target-domain> | grep "ba_token" and similar archive queries against other PayPal-integrated merchants. A positive result is a set of tokens that still resolve to a nonce at some merchant ID.
  3. Merchant ID enumeration. Test harvested tokens against multiple public client IDs. A positive result is any merchant whose endpoint returns the victim's billing details or a usable nonce.
  4. Third-party leakage. Check analytics and other third-party requests on checkout pages for billingAgreementToken values. A positive result is a token appearing in a request to a domain that is not the payment provider.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

Imagine you pay for something online with PayPal. During checkout, PayPal hands the shop a short-lived reference number that stands in for your payment details, so the shop never sees your actual account. That reference number is called a token. The shop's own computer system (its server) is supposed to swap that token for a one-time code, called a nonce, which it then uses to charge you.

The researcher found that the service doing this swap, run by a payment company called Braintree (owned by PayPal), did not check who was asking. Anyone who had somebody else's token could ask Braintree to produce a fresh nonce for that person, and with that nonce make a payment from the victim's PayPal account. The researcher also showed that these tokens are easy to find lying around on the public web.

This kind of flaw, where a system lets you reach another person's data just by supplying their identifier, is called an Insecure Direct Object Reference, or IDOR. A simple comparison: a cloakroom that gives you a ticket with a number, and then hands out any coat whose number you name, without checking that the ticket is yours.

Below I walk through the whole thing from zero: what each piece is, what was done, and why.

Background: the pieces involved

What an API is

An API (Application Programming Interface) is a way for two computer programs to talk to each other. Think of a restaurant: you do not walk into the kitchen, you tell the waiter what you want and the waiter brings it. The waiter is the API. In this story, the shop's website (Grammarly) is the customer, and Braintree's servers are the kitchen that handles payments.

What Braintree is

Braintree is a payment gateway owned by PayPal. A payment gateway is a service that sits between a shop and the payment networks, taking care of the sensitive part of moving money. Shops that want to accept PayPal or cards integrate with Braintree through a web address, api.braintreegateway.com. A shop that uses Braintree in this way is called a merchant.

What a payment method nonce is

One of the building blocks of that integration is the payment method nonce: a secure, one-time-use reference to payment information. It lets a merchant's server talk to Braintree without ever handling raw card or PayPal data. The report quotes the vendor documentation for this:

A payment method nonce is a secure, one-time-use reference to payment information. It’s the key element that allows your server to communicate sensitive payment information to Braintree without ever touching the raw data.

In everyday terms, a nonce is like a numbered claim ticket at a dry cleaner: it stands for your coat, it can be used once, and the person holding it does not need to carry the coat around.

What a billingAgreementToken is

For PayPal payments, the nonce is derived from a billingAgreementToken, a value that PayPal passes around during the checkout flow. Think of it as the reference number on an order slip that travels between PayPal and the shop while you are checking out. The endpoint that turns a billingAgreementToken into a payment method nonce is:

Text
api.braintreegateway.com/merchants/<ID>/client_api/v1/payment_methods/paypal_accounts

Reading that address from left to right: api.braintreegateway.com is Braintree's server; merchants/<ID> identifies which shop is asking (the <ID> is a placeholder for the shop's identifier); client_api/v1/payment_methods/paypal_accounts is the particular function being called, here the one that deals with PayPal accounts as payment methods.

What the researcher expected

The researcher's argument is that this endpoint should be authenticated by the merchant, because it is the merchant's server that is supposed to exchange the token for a nonce. Authentication here means proving who you are before being allowed to do something, like showing a membership card at a club door. Instead, the researcher found that a user (or anyone) can send POST requests to it directly and generate payment method nonces. A POST request is one of the standard ways a browser or program asks a server to do something, usually to send data; a GET request, mentioned later, is the way a browser asks a server to fetch a page or resource.

Setting up the test

The work was done against a real merchant that uses Braintree: Grammarly, the writing-assistant service. The researcher reproduced the issue against Grammarly, opening the victim's PayPal account and repeating the same checkout steps. A proxy is a program that sits between your browser and the internet and lets you look at, pause and change the messages going back and forth; Burp is a well-known tool for this. "Replay" means sending the same captured message again, possibly with changes.

The merchant identifier used throughout is Grammarly's public client ID, 68r2vzdxyjwst8d7, which the report notes explicitly is public. A client ID is a label that tells the payment service which shop a request belongs to; it is not a secret, much like a shop's name on a sign.

The precondition for the attack is possession of a valid billingAgreementToken belonging to another user. The report spends a section on how such tokens can be obtained, so that precondition is not as strong as it sounds.

Finding it

While reading the Braintree documentation on payment method nonces, the researcher reasoned that if a valid billingAgreementToken of another user could be obtained, it would be possible to generate a new nonce and then make a payment. The question was whether the nonce-generation endpoint enforced any authentication of its own. It did not: the endpoint accepts POST requests from the user directly, so a token is enough.

Exploitation

Step 1: start a PayPal checkout at the merchant

  1. Go to https://www.grammarly.com/upgrade and log in with your account.
  2. Choose your plan and select PayPal as the payment method, with an intercepting proxy in place.
  3. Click on PayPal checkout and accept the payment.
  4. When the request below appears, drop it, which cancels the payment.
HTTP
POST /api/v1/subscribe HTTP/1.1Host: subscription.grammarly.comConnection: closeContent-Length: 135Cookie: <>nonce=<nonce>&planId=1005&sessionId=<sessionId>&isTaxable=false&billingCountryCode=US

Line by line, in plain words:

  • POST /api/v1/subscribe HTTP/1.1 says: send a POST request to the path /api/v1/subscribe, using version 1.1 of the HTTP protocol (the language browsers and servers speak).
  • Host: subscription.grammarly.com names the server being contacted, here Grammarly's subscription service.
  • Connection: close asks that the connection be closed after this exchange.
  • Content-Length: 135 states how many bytes of data follow.
  • Cookie: <> is where the browser's cookie would go. A cookie is a small piece of data a website stores in your browser so it can recognise you on later requests, like a wristband at an event. The angle brackets are placeholders, so the actual value is not shown.
  • The last line is the body of the request: nonce=<nonce>&planId=1005&sessionId=<sessionId>&isTaxable=false&billingCountryCode=US. The & signs separate fields. nonce=<nonce> is the payment method nonce, planId=1005 is the chosen plan, sessionId=<sessionId> identifies the browsing session, isTaxable=false says the purchase is not taxable, and billingCountryCode=US gives the billing country.

Why this step: it shows that Grammarly's own subscription endpoint consumes a payment method nonce (nonce=<nonce>), which is the value the attack will forge. In other words, we first see where the nonce is used, so that later we understand what producing one is worth.

Step 2: locate the nonce-generation request

Back in the proxy history, find this endpoint and send it to the repeater:

Text
https://api.braintreegateway.com/merchants/68r2vzdxyjwst8d7/client_api/v1/payment_methods/paypal_accounts

This is the same address described earlier, now with Grammarly's real client ID filled in. The repeater is a feature of the proxy that lets you take a captured request and send it again as many times as you like, changing it between attempts. Why: we want to experiment with this one request without going through the whole checkout each time.

Step 3: obtain the victim's token

Open the victim's PayPal account and repeat the same checkout steps, then copy the billingAgreementToken from the victim's flow. Why: the attack needs a real, valid token belonging to somebody else; the victim's own checkout is the easiest place to see one.

Step 4: swap the token

Change the billingAgreementToken in the request to api.braintreegateway.com/merchants/68r2vzdxyjwst8d7/client_api/v1/payment_methods/paypal_accounts to the victim's token. The report notes again that 68r2vzdxyjwst8d7 is Grammarly's public client ID.

From the original on medium.com

The image relates to changing the billingAgreementToken to the victim's token at the Grammarly merchant endpoint.

The response contains nonces generated from the victim's billingAgreementToken, and no specific authentication is needed to get them. Why this matters: the server did not ask who was calling. It simply took the token it was given and produced a usable nonce, which is the IDOR at the heart of the report.

Step 5: obtaining tokens for other users

The researcher then addresses the obvious objection: where does an attacker get a valid billingAgreementToken? The report lists several sources.

Wayback Machine

Tools such as waybackurls and gau fetch known URLs for a domain from the Wayback Machine and other archives. The Wayback Machine is a public archive that keeps copies of web pages over time, like a library of old snapshots of the internet. waybackurls and gau are free command-line tools that collect web addresses the archive has seen for a given domain. The command used was:

Wait, the command in the report is:

Bash
gau paypal.com | grep "ba_token"

Line by line:

  • gau paypal.com asks the tool to list known addresses for the domain paypal.com.
  • The vertical bar | means "take the output of the left command and feed it into the right one".
  • grep "ba_token" filters that list, keeping only lines that contain the text ba_token, which is the short name for the billing agreement token in URLs.

Why: if a token ever appeared in a web address that was archived, this finds it.

From the original on medium.com

The image relates to the gau tool and the command gau paypal.com | grep "ba_token".

The result is a large number of leaked billingAgreementToken values in the Wayback Machine, which the researcher attributes to the token being a public token. The attacker's next step is to find a merchant that will accept one of those tokens: if a token was used at Grammarly, the attacker sends the POST request to the Grammarly merchant endpoint and receives the user's PayPal information. This requires finding the right merchant ID and testing the tokens against it, which the researcher considers feasible given how many companies use the Braintree gateway.

Google dorking

Because the billingAgreementToken is passed in a GET request, some of them can be found on Google with a dork. A Google dork is a search query built with special operators to find pages that ordinary searches would not surface, for example pages that contain a particular parameter. The researcher notes there is not much there.

From the original on medium.com

The image relates to the Google dork and the researcher's remark that there is not much to find this way.

Leakage to third parties

The researcher also found the billingAgreementToken leaked to third parties, for example Google Analytics. Google Analytics is a service many websites use to measure visitor traffic; it receives information about page visits, and if a token ends up in a request sent to it, the token leaves the payment flow and lands in someone else's systems.

From the original on medium.com

The image relates to the billingAgreementToken leaking to a third party such as Google Analytics.

Root cause

Missing authentication on a sensitive endpoint. The endpoint api.braintreegateway.com/merchants/<ID>/client_api/v1/payment_methods/paypal_accounts is meant to be called by the merchant, but it accepts requests from the user and generates payment method nonces from whatever billingAgreementToken is supplied. The researcher's view is that the only parties who should have access are merchants using their API keys, since api.braintreegateway.com has many authentication endpoints and this one should behave the same way. An API key is a secret string that identifies a program to a service, like a password for software. The researcher's view is that the endpoint should require merchant authentication, as other endpoints on api.braintreegateway.com do.

Impact

An attacker who holds a valid billingAgreementToken can expose PayPal user data: billing address, email and nonce code. Because the same endpoint generates a valid nonce that can be used to make a payment to the merchant, an attacker can make payments from PayPal victims' accounts. The report notes the attacker needs to find the right merchant ID and test the tokens against it.

From the original on medium.com

The image relates to the endpoint used to generate a valid nonce, the impact note and the HackerOne triage response.

Fix

The report does not say what was changed. The researcher's recommendation is that the endpoint must be authenticated, with access limited to merchants using their API keys, consistent with the other authentication endpoints on api.braintreegateway.com.

  1. Other Braintree client endpoints. Enumerate client_api paths under a merchant ID and replay them without merchant credentials. A positive result is a response containing payment method data or a nonce for a token you supplied.
  2. Token sources. Run gau <target-domain> | grep "ba_token" and similar archive queries against other PayPal-integrated merchants. A positive result is a set of tokens that still resolve to a nonce at some merchant ID.
  3. Merchant ID enumeration. Test harvested tokens against multiple public client IDs. A positive result is any merchant whose endpoint returns the victim's billing details or a usable nonce.
  4. Third-party leakage. Check analytics and other third-party requests on checkout pages for billingAgreementToken values. A positive result is a token appearing in a request to a domain that is not the payment provider.

Glossary

  • API: a way for two computer programs to talk to each other, like a waiter carrying requests between a customer and a kitchen.
  • API key: a secret string that identifies a program to a service, like a password for software.
  • Authentication: proving who you are before being allowed to do something, like showing a membership card at a club door.
  • Braintree: a payment gateway owned by PayPal that shops use to accept payments.
  • billingAgreementToken: a value PayPal passes around during checkout that stands in for a user's payment agreement and can be exchanged for a nonce.
  • Burp: a well-known proxy tool for looking at, pausing and changing traffic between a browser and the internet.
  • Client ID: a public label that tells a payment service which shop a request belongs to.
  • Cookie: a small piece of data a website stores in your browser so it can recognise you on later requests, like a wristband at an event.
  • GET request: the standard way a browser asks a server to fetch a page or resource.
  • Google Analytics: a service many websites use to measure visitor traffic, which receives information about page visits.
  • Google dork: a search query built with special operators to find pages ordinary searches would not surface.
  • gau: a free command-line tool that collects web addresses an archive has seen for a domain.
  • grep: a command-line tool that filters text, keeping only lines that match a pattern.
  • HackerOne: a platform where security researchers report vulnerabilities to companies.
  • HTTP: the language browsers and servers speak to exchange requests and responses.
  • IDOR (Insecure Direct Object Reference): a flaw where a system lets you reach another person's data just by supplying their identifier, without checking that it is yours.
  • Merchant: a shop that uses a payment gateway such as Braintree.
  • Nonce: a secure, one-time-use reference to payment information, like a numbered claim ticket at a dry cleaner.
  • Payment gateway: a service that sits between a shop and the payment networks and handles the sensitive part of moving money.
  • POST request: a standard way a browser or program asks a server to do something, usually sending data along with it.
  • Proxy: a program that sits between your browser and the internet and lets you look at, pause and change the messages going back and forth.
  • Repeater: a proxy feature that lets you resend a captured request as many times as you like, changing it between attempts.
  • Token: a short-lived reference value that stands in for something sensitive, so the sensitive thing itself does not have to be passed around.
  • Wayback Machine: a public archive that keeps copies of web pages over time, like a library of old snapshots of the internet.
  • waybackurls: a free command-line tool that lists web addresses the Wayback Machine knows about for a domain.

More by Souhaib Naceri

View all

2 more disclosed reports, best first.

More from PayPal

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Insecure direct object reference (IDOR)

The lesson behind this report.

One user can read or change another user's data, usually by changing an identifier the server trusts without checking who is asking. One of the most paid bug classes on web programs.