Your Agent Just Paid for Nothing: 6 Attacks on x402 Payments - Ishween Kaur, SoFi

AI Engineer · 16 min · 179 sentences · from YouTube's caption track

Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.

  1. 00:01[music]
  2. 00:12Hi everyone.
  3. 00:12I'm Ishreen Kaur.
  4. 00:13I work at AI evaluation and autonomous systems, but today I got interested into agentic payments and that's when I explored X402 and started to attack it in a safe environment.
  5. 00:24X402 protocol is still in a West Wild and I can understand from the attendance of the audience that while it's still there, uh but going ahead like I would first want to understand
  6. 00:35how many of you have paid for subscription just to use something once?
  7. 00:41Many of us, yeah, exactly.
  8. 00:42Now, imagine you want to watch this one movie that is available on Disney Plus.
  9. 00:47Just this one movie.
  10. 00:48You do not even want Disney Plus for next 6 days.
  11. 00:51What you do today is to create an account, start a subscription, enter your payment information, watch that one movie, and you need to remember to cancel yourself.
  12. 01:00What if internet would have made it simpler for me is to just pay, request, pay, and receive what I want.
  13. 01:07And now replace yourself with an agent.
  14. 01:10An agent is trying to create a report for you, and it needs one market data point that is available on this API that says, "Hey, pay me 5 cents."
  15. 01:19Should your agent just pay?
  16. 01:21Probably not.
  17. 01:22It should ask, "Is this seller allowed?
  18. 01:24Is this the amount within my budget?
  19. 01:26Is this the data what I approved for?"
  20. 01:28And if answers are yes, yeah, paid.
  21. 01:32Now, HTTP had a status code 402 for decades.
  22. 01:37It was a placeholder.
  23. 01:39It said that payment is required, but it never said how a machine can actually pay.
  24. 01:44And X402 started to fill that gap by explaining how a machine can actually pay.
  25. 01:51And Cloudflare is exploring it by paper crawl where publishers are actually pushing the data with saying, "Hey, pay me these money."
  26. 01:59And it moving beyond saying allowing or blocking.
  27. 02:02So, it is interesting to see that software is becoming a buyer now.
  28. 02:09Now, what is XF02, and how does it work?
  29. 02:13It has four entities, buyer, seller, facilitator, and a chain.
  30. 02:17The buyer asks for the data.
  31. 02:19It represents you or your organization.
  32. 02:21The seller has the data, and it will say 402 and the payment requirements.
  33. 02:26The buyer is going to sign that payment.
  34. 02:29Now, a seller is going to send that to facilitator for verification and settlement.
  35. 02:35It sends a valid signal if verification is a success, which is essentially verifying the signature of the buyer request, and then it can send a valid signal to seller to release the data, or can say like, "Hey, wait for settlement phase to move the payments,
  36. 02:48and then I'll send the data."
  37. 02:52Now, the interesting thing to notice is why on chain, why not credit card?
  38. 02:56So, if you see, these are micro payments, like 10 cents, 1 cent, 1/3 of a cent.
  39. 03:01If the transaction fee of a credit card is more than the thing that you are trying to buy, the payment itself become expensive, and it's illogical.
  40. 03:09And if you observe closely, the 10 cents * 10,000 calls means $1,000 of payments moving on machine.
  41. 03:18So, your payments needs to scale with agents.
  42. 03:24Now, if you have built agents, you would have had autonomy conversations with yourself or with your colleagues that agent writes code, human is going to approve it.
  43. 03:32Agent is going to draft an email, human is going to review that email and click that send.
  44. 03:37Now, put payment on the other side of this line, agent can now pay.
  45. 03:41But, agent doesn't have to be even broken to lose money.
  46. 03:45And so, that's when I ask myself, what happens when I let my agent pay?
  47. 03:50So, I was able to break this entire sequence in 20 different ways, and today I'm going to speak about six on the buyer and the seller side to see what it looks like to make it into production.
  48. 04:01I'll give a sec.
  49. 04:02Okay.
  50. 04:05Now, the very first attack that I did was about price manipulation.
  51. 04:08Now, I mentioned that a buyer is going to find a seller in a directory.
  52. 04:12Now, that seller can list I'm available for 5 cents.
  53. 04:16But, the actual payment comes in that header when we say 402 and the payment requirement.
  54. 04:21And that header can change the price any moment in the last seconds.
  55. 04:25And so, what if my buyer would have said like, "Okay, I I asked 50 cents.
  56. 04:29I listed 5 cents.
  57. 04:30I don't care."
  58. 04:31Now, I was running this experiment and I create my own uh observability gra- diagrams where the run one was without any guard when I didn't added guard and it actually paid settled 50 cents
  59. 04:46when the listed price was 5 cents.
  60. 04:50So, and the next run when I did with the guard, it actually blocked it.
  61. 04:56The reason it blocked essentially is because the buyer knows the listed price and the seller price.
  62. 05:01Can't I do just code check of the two fields?
  63. 05:05And that stopped my attacks, but it also uh didn't stop other attacks which was changing the wallet or the network.
  64. 05:11Now, today I'm on base, tomorrow I'm on Ethereum or Solana.
  65. 05:14Then, my wallet network is changing.
  66. 05:16My wallet address can rotate and so, I need to check each of these fields to make sure that I'm paying the right seller the right amount.
  67. 05:23So, we paid the right amount.
  68. 05:24What if we pay the right amount twice?
  69. 05:27A payment number is unique on chain and a duplicate payment number gets canceled on the chain.
  70. 05:33Now, the buyer tries to send same payment number one, let's say, five times to the seller.
  71. 05:39Seller is going to send that request to facilitator.
  72. 05:42On the verification phase, we will just check the signatures and it will say, "Okay, I'm I'm valid."
  73. 05:48Like, these requests look valid, so let's deliver the data.
  74. 05:51And the seller will deliver the data.
  75. 05:53But, during the settlement phase, essentially, one is going to get settled and four will get rejected because payment number needs to be unique on chain.
  76. 06:03And the fix is simple because you can just have a shared storage where you can store all your payment numbers and be like these were already done or these are in progress and if any other payment number comes for the same, I'm I can share the saved copy.
  77. 06:18Now this matters because if you have expensive data, confidential data, licensing activation uh and you are releasing those four different data to that same buyer in these four different requests on the same payment number, you are losing your data.
  78. 06:35Now this same attack can happen on the buyer's side also.
  79. 06:38For the retries.
  80. 06:40Let's say a reply a reply timed out and I am doing a retry and I have a retry limit of three, but every retry is done with the with a different payment number.
  81. 06:49And so you are going to get three charges for one summary that might be useful for you.
  82. 06:53So be cautious when you are doing retries to use the same payment number uh so that only one charge happens.
  83. 07:03Now the attack three was about free shopping.
  84. 07:06Can I get things for free?
  85. 07:07Now the buyer sends the payment request to the seller.
  86. 07:10Seller is good.
  87. 07:11Facilitator says valid and you deliver the data.
  88. 07:14But during the settlement because of some insufficient funds in the buyer or inconsistent state, the payment gets reverted.
  89. 07:23The fix looks simple that let's wait for settlement phase actually to happen and then release the data.
  90. 07:28But that comes with a trade-off between the latency and the risk for the business use case you want to solve.
  91. 07:33If the data is expensive, uh it's licensing or activation, it's provisioning, it is confidential data, it needs to be generated every request, then yes, waiting for settlement phase is a good choice.
  92. 07:44But if data is at the cost of dollar to send the data on the valid signal for performance reasons.
  93. 07:55Now the other way that free shopping can happen, let's say if you have two pages on delivering the same report.
  94. 08:01One is behind the paywall while another is not.
  95. 08:04And the buyer knows about the one which is not behind the paywall and he tries to hit that endpoint which can happen which happens a lot actually in software industry.
  96. 08:13So, the test is simple that call every endpoint that you want behind the paywall and it should give you 402.
  97. 08:21The third way that free shopping can happen is if you have cash for performance reasons on the seller side.
  98. 08:28Now, your buyer sent a request to the seller, the seller sends the data, but it also cached the results for performance reason.
  99. 08:36But, this cache is by default on the public URL.
  100. 08:39And so, any subsequent buyer can hit that public URL on the cache and get the data for free.
  101. 08:46The fix is two parts.
  102. 08:47To have your cache on the server be on the seller side behind the paywall.
  103. 08:52So, that you do a price check before releasing the saved data.
  104. 08:57The second thing is if the data is getting generated every time, it's confidential or it's expensive, don't cache it.
  105. 09:03There is a header in the cache with a cache control saying no store, which can essentially not going to store your data in the cache.
  106. 09:13Now, for the fourth attack, we are done with three attacks, is that you have a seller which has multiple pages behind the paywall.
  107. 09:21But, they don't speak to each other.
  108. 09:23They don't know about each other.
  109. 09:24Now, you do one payment which is payment number essentially 16 in this case and you fire the same to the both the pages.
  110. 09:31They don't know and so, they are valid.
  111. 09:34They deliver the data.
  112. 09:36But, during the settlement phase, we know only one going to get settled because of payment number has to be unique.
  113. 09:44So, the fix is we Remember, we had the shared storage and in the shared storage, we can have that claim number binded with the mapping of the page that you actually delivered.
  114. 09:54So, that if any other delivery wants to happen on the same payment number, you can say 409 conflict and your data is secured there.
  115. 10:04Attack number five is about the malicious discovery.
  116. 10:07Now, how does buyer finds these sellers?
  117. 10:10Buyer finds these sellers in a directory called Bazaar in X402 and it checks for that service works, but it doesn't check who runs it and who owns the wallet.
  118. 10:20So, what if I create a look-alike of a real seller and I have a different domain now, different wallet, different price, but similar name or same name.
  119. 10:30And my agent tried to pick that one because it was a cheaper cost.
  120. 10:34And what if that look-alike is an attacker to you?
  121. 10:39And so you actually give that to an attacker.
  122. 10:42So, this is the suggestion that to have enterprises which are conservative to have an allow list of sellers that we do to only allow those sellers that are approved by your enterprises.
  123. 10:53But when we are trying to do agentic workflows, we want to explore new different sellers always.
  124. 10:58And in that case, having an allow list, block list, and approbation list helps where the new sellers that you discover, you can add it to probation list.
  125. 11:06A human can review later.
  126. 11:09You can have a cap like 4 hours, 24 hours of how your probation list gets filled out to understand what was the buyer's intent, what did the seller responded, and which seller was called.
  127. 11:19Because even the honest sellers, they also rotate their domains, they rotate their wallet, and they rotate their price or network and coin.
  128. 11:28And doing a fast check always won't help in knowing that the allow list is always true.
  129. 11:34So, keeping the allow list active is the goal here to explore the right sellers.
  130. 11:43Now, the attack number six is I think it might bring a lot of things together also about prompt injection.
  131. 11:48So, the reply from the seller are text.
  132. 11:51If it says like this summary is truncated, the full version is at premium summary.
  133. 11:57It's just a suggestion.
  134. 11:57It doesn't said like what you need to do.
  135. 12:00Now, while I was running, uh I actually used I Let me see if I Yeah.
  136. 12:07Actually used Llama 3.2 and uh just want to mention that the test that I was running was on uh base Sepolia and I use x402 off facilitator uh local test net here.
  137. 12:19So, I was using llama 3.2 to decide like what to do when the seller's reply is about the premium summary.
  138. 12:26The agent decided to actually fetch from the premium summary and it paid again.
  139. 12:31So, what would have costed me 5 cents actually costed me 55 cents.
  140. 12:36So, in this run when I did without any guard, if you see there is a premium summary that gets paid here.
  141. 12:43And so, the 5 cents and 50 cents both get settled.
  142. 12:46But, in the second run the same thing happened where the agent agent still decided to fetch it, but it got blocked.
  143. 12:54Now, when I was experimenting with understanding how can I block these prompt injections, is essentially I tried two other different ways before coming into this is rejects check.
  144. 13:05So, you know some filter words filler words like pay tiers premium and if you see that in your in the seller's response, you can be like, "Okay, this is an attack to me."
  145. 13:15But, it would not catch those quite hints like if it says analyst usually prefers quality summary go to this.
  146. 13:23And it's not an attack direct attack to the buyer.
  147. 13:28And the other way is to have a model to actually see whether it's an attack or not, which actually works pretty well in most of the cases, but there could be attacks
  148. 13:36where it won't pick the it won't judge that it is an attack.
  149. 13:41So, what I did was that I know that in this particular turn in this run, I want my buyer to call only once.
  150. 13:49And so, it should never call twice to any other seller in this particular turn.
  151. 13:54That reduced my risk area and that is why I locked this plan to execute only once and that's when it got blocked even if the agent decided to pay to the premium summary.
  152. 14:06So, that brought my attacks to zero here.
  153. 14:09Um yeah.
  154. 14:11I think the pattern that I want to give is um the payment can look right like most of the cases my payments look right, but I got the wrong outcome.
  155. 14:20And so checking before the buyer gives the signing of the payment or checking before the seller gives the data is essentially needed and our traces should speak about those.
  156. 14:31So, how to actually roll out to production or like how to experiment with these when I try to do it with in 20 different ways is essentially I used one payment ID and started to log
  157. 14:42entire sequence diagram.
  158. 14:44So, for your specific business use case you would be having an identic system workflow.
  159. 14:49Start with one payment ID and trace it throughout that system.
  160. 14:52That one payment ID should give you enough traces to help you understand what was the buyer's intent, what did seller responded and which seller was called.
  161. 15:00If it's not giving then you need to add more traces to it.
  162. 15:03So, that answers when you get you would then go to shadow phase where you will create 20 to 25 data set of success and a failure and perform error analysis
  163. 15:13on them.
  164. 15:14To understand where do you need guards, where do you need alerting and where do you need blocking this.
  165. 15:20Those error analysis will then become in enforcement where you'll add guards, you'll add alerting and then you'll perform that same mechanism of tracing every time with these 20 to 25 different data set
  166. 15:35to understand are these guards enough?
  167. 15:38Do we want to get more aggressive or do we want to release these guards or still add just alerts or are we lenient?
  168. 15:45Those questions will come those answers will actually come from these questions of going through those specific business use case and this is the work that matters.
  169. 15:54If you remember the presentation before me mentioned about 65 industry benchmarks, they did trace by trace and so each thing needs to be done trace by trace to truly understand
  170. 16:05what it is actually trying to perform.
  171. 16:08Um yeah, with that I think I would just say this is the handbook that I created to share it with you to like how I added the code and you can actually
  172. 16:18run it in the base Bolyai and have your own um runs there.
  173. 16:23Can our agents pay?
  174. 16:24Yes, but the real question is should we let them pay?
  175. 16:28Yes, but now you know where to look it at.
  176. 16:31Thank you.
  177. 16:31I'll be outside for any questions and answers.
  178. 16:35Thank you.
  179. 16:36[applause]