<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://stablevoy.com/blog/</id>
<title>Stablevoy blog</title>
<subtitle>Stablecoin payments, from the code up.</subtitle>
<link rel="self" type="application/atom+xml" href="https://stablevoy.com/blog/feed.xml"/>
<link rel="alternate" type="text/html" href="https://stablevoy.com/blog/"/>
<updated>2026-11-27T00:00:00Z</updated>
<author><name>Stablevoy</name></author>
<entry>
<id>https://stablevoy.com/blog/create2-deposit-addresses/</id>
<title>One deposit address per invoice with CREATE2</title>
<link rel="alternate" type="text/html" href="https://stablevoy.com/blog/create2-deposit-addresses/"/>
<published>2026-11-27T00:00:00Z</published>
<updated>2026-11-27T00:00:00Z</updated>
<summary>A fresh address for every invoice with no private key behind it: how CREATE2, EIP-1167 clones and a salt bound to the payout wallet make it work.</summary>
<category term="solidity"/>
<category term="ethereum"/>
<category term="web3"/>
<category term="security"/>
<content type="html">&lt;p&gt;A payment gateway has to answer one question for every transfer it sees: which order is this for? The cleanest answer is a fresh address for every invoice. The hard part is doing that without a private key for each address sitting on a server. CREATE2 solves it: the address is known before anything exists on the chain, nobody holds a key for it, and the contract that later appears there can only send the money to one wallet.&lt;/p&gt;&lt;p&gt;This post shows how that works, with the formula, the code that computes the address off-chain, and a run on a local chain where a payment lands on an address that has no code yet.&lt;/p&gt;&lt;h2 id=&quot;options&quot;&gt;Three ways to tell payments apart&lt;/h2&gt;&lt;div class=&quot;table-wrap&quot;&gt;&lt;table class=&quot;table&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;One wallet, amount tail&lt;/th&gt;&lt;th&gt;A key per invoice (HD wallet)&lt;/th&gt;&lt;th&gt;A CREATE2 forwarder per invoice&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;How a payment is matched&lt;/th&gt;&lt;td&gt;By an exact amount such as 10.001&lt;/td&gt;&lt;td&gt;By the address&lt;/td&gt;&lt;td&gt;By the address&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Who can move the funds&lt;/th&gt;&lt;td&gt;The merchant&lt;/td&gt;&lt;td&gt;Whoever holds the derived keys&lt;/td&gt;&lt;td&gt;Nobody; the code sends them to the merchant&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Keys on a server&lt;/th&gt;&lt;td&gt;No&lt;/td&gt;&lt;td&gt;Yes, or the merchant moves every payment by hand&lt;/td&gt;&lt;td&gt;No&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Gas to move a token payment&lt;/th&gt;&lt;td&gt;None, it is already in the wallet&lt;/td&gt;&lt;td&gt;Native coin must be sent to every address first&lt;/td&gt;&lt;td&gt;Paid once by whoever calls sweep&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;What goes wrong&lt;/th&gt;&lt;td&gt;An overpayment or a rounded amount matches no order&lt;/td&gt;&lt;td&gt;A leaked seed empties every open invoice&lt;/td&gt;&lt;td&gt;A payout wallet that does not exist on the network&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;The amount tail is simple and costs nothing, and Stablevoy uses it on Tron, where it pays out straight to the merchant&apos;s wallet. On EVM networks the forwarder gives what the other two cannot give together: a payment is matched by its address, whatever amount arrives, and no key for that address exists anywhere.&lt;/p&gt;&lt;h2 id=&quot;formula&quot;&gt;The CREATE2 formula&lt;/h2&gt;&lt;p&gt;A contract deployed with CREATE2 (&lt;a href=&quot;https://eips.ethereum.org/EIPS/eip-1014&quot; rel=&quot;noreferrer&quot;&gt;EIP-1014&lt;/a&gt;) lands at an address that depends only on three things: the deployer, a 32-byte salt and the hash of the code being deployed. Same inputs, same address, on any EVM network (the &lt;a href=&quot;https://stablevoy.com/networks/&quot;&gt;networks page&lt;/a&gt; lists the ones Stablevoy runs on).&lt;/p&gt;&lt;figure class=&quot;post-figure&quot;&gt;&lt;img src=&quot;https://stablevoy.com/blog/create2-deposit-addresses/create2-formula.svg&quot; alt=&quot;The salt is keccak256 of the invoice salt, the merchant wallet and the fee; then 0xff, the factory address, the salt and the hash of the clone init code are hashed with keccak256, and the last 20 bytes are the deposit address&quot; width=&quot;760&quot; height=&quot;400&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;&lt;figcaption&gt;The salt commits to the payout wallet and the fee, so neither can change without moving the address.&lt;/figcaption&gt;&lt;/figure&gt;&lt;p&gt;The trick is what goes into the salt. Stablevoy&apos;s factory does not use the random invoice salt as it is. It hashes it together with the merchant&apos;s payout wallet and the fee rate:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Solidity salt of the factory&quot; data-language=&quot;solidity&quot;&gt;&lt;code&gt;function _salt(bytes32 invoiceSalt, address merchant, uint16 feeBps) private pure returns (bytes32) {
    return keccak256(abi.encode(invoiceSalt, merchant, feeBps));
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The forwarder deployed at the address is told the merchant and the fee by the same call that deploys it. Change the wallet in that call and the factory deploys somewhere else: the funds already sitting at the original address stay there, still waiting for the right parameters. In the run below, the same invoice with another payout wallet gives a completely different address.&lt;/p&gt;&lt;p&gt;The code being deployed is not the full forwarder, but a 55-byte&lt;!-- --&gt; &lt;a href=&quot;https://eips.ethereum.org/EIPS/eip-1167&quot; rel=&quot;noreferrer&quot;&gt;EIP-1167&lt;/a&gt; &lt;!-- --&gt;clone that delegates every call to one forwarder implementation. Its init code hash is the same for every invoice, which keeps the formula cheap to compute and the deployment cheap to pay for.&lt;/p&gt;&lt;h2 id=&quot;compute&quot;&gt;Compute the address off-chain&lt;/h2&gt;&lt;p&gt;Nothing in the formula needs the chain, so the address can be computed in a few lines with ethers.js:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;ethers.js deposit address&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;import { AbiCoder, concat, getAddress, getCreate2Address, keccak256 } from &apos;ethers&apos;;

// The CREATE2 address of an invoice&apos;s deposit forwarder, computed off-chain (EIP-1014, EIP-1167 clone).
export function depositAddress({ factory, implementation, invoiceSalt, merchant, feeBps }) {
  // 1. The salt commits to the invoice, the payout wallet and the fee rate.
  const salt = keccak256(AbiCoder.defaultAbiCoder().encode([&apos;bytes32&apos;, &apos;address&apos;, &apos;uint16&apos;], [invoiceSalt, merchant, feeBps]));
  // 2. The init code is the 55-byte EIP-1167 clone of the forwarder implementation.
  const initCode = concat([&apos;0x3d602d80600a3d3981f3363d3d373d3d3d363d73&apos;, getAddress(implementation), &apos;0x5af43d82803e903d91602b57fd5bf3&apos;]);
  // 3. address = last 20 bytes of keccak256(0xff ++ factory ++ salt ++ keccak256(initCode))
  return getCreate2Address(getAddress(factory), salt, keccak256(initCode));
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is also what the Stablevoy payment page does in the buyer&apos;s browser before it shows an address, with one difference: the factory and implementation addresses are built into the page instead of taken from the server. An address that the factory would not create for this invoice, its payout wallet and its fee is never shown. The payout wallet itself comes from the store settings, where it changes only with the merchant&apos;s wallet signature.&lt;/p&gt;&lt;p&gt;Checked against the deployed factory with a read-only call, the function gives the same address the factory computes, and the factory gives the same address on Base and on Arbitrum:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;the deployed factory and the function&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;base factory:     0x8CaCa524ed0C01c04C5bD1DB473e5FB7b0D7b2f7
arbitrum factory: 0x8CaCa524ed0C01c04C5bD1DB473e5FB7b0D7b2f7
off-chain:        0x8CaCa524ed0C01c04C5bD1DB473e5FB7b0D7b2f7&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;lifecycle&quot;&gt;Pay first, deploy later&lt;/h2&gt;&lt;p&gt;The part that surprises most people: the buyer pays an address where no contract exists yet. An address on an EVM chain is just a key in the state; it can hold a balance with no code behind it. The contract only appears when someone collects the money.&lt;/p&gt;&lt;figure class=&quot;post-figure&quot;&gt;&lt;img src=&quot;https://stablevoy.com/blog/create2-deposit-addresses/lifecycle.svg&quot; alt=&quot;Three steps: the invoice address is computed with no transaction; the buyer pays it while it still has no code; anyone calls sweep, which deploys the 45-byte clone and splits the balance, 99.5 to the merchant and 0.5 to the fee recipient&quot; width=&quot;760&quot; height=&quot;430&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;&lt;figcaption&gt;One transaction deploys the forwarder and flushes it. Invoices that are never paid never cost gas.&lt;/figcaption&gt;&lt;/figure&gt;&lt;p&gt;Here is the whole cycle on a local Anvil chain: the factory deployed with a 2% fee cap, an invoice at 0.5%, 100 ETH paid before deployment, and the sweep called by an account that is neither the merchant nor the operator. The run uses the native coin to stay short; a token goes through &lt;code&gt;sweep&lt;/code&gt; with the token address in exactly the same way.&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;output of the local run&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;computed off-chain  0x02794c60ECBB6b0ad1e112Eb6667Fd17fA1580C3
factory says        0x02794c60ECBB6b0ad1e112Eb6667Fd17fA1580C3
code at the address 0x
paid 100 ETH, balance 100.000000000000000000, still no code: 0x
after the sweep by a stranger:
  merchant      99.500000000000000000 ETH
  fee recipient 0.500000000000000000 ETH
  deposit addr  0.000000000000000000 ETH, code size 45 bytes
same invoice, other wallet: 0xb850ddf074A240327c3c17C8D2E4Da319Bd02D59
fee 201 bps: FeeAboveCap(201, 200)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The stranger paid the gas and received nothing. That is the point: sweeping is open to anyone because the caller has no say in where the money goes. Stablevoy normally sweeps and pays the gas itself, but if it stopped, the merchant, the buyer or anyone else could call the same function. The&lt;!-- --&gt; &lt;a href=&quot;https://stablevoy.com/docs/recovery/&quot;&gt;recovery guide&lt;/a&gt; walks through doing that by hand.&lt;/p&gt;&lt;h2 id=&quot;guarantees&quot;&gt;What the contracts refuse to do&lt;/h2&gt;&lt;p&gt;The security of this design is mostly in what is missing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Nobody can get to the address first.&lt;/strong&gt; Only the factory can deploy there, since the deployer is part of the formula, and it binds the forwarder to the merchant in the same transaction that creates it.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;No owner and no upgrade path.&lt;/strong&gt; The factory has no admin functions. The fee recipient and the fee cap are immutable, set once in the constructor.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A capped fee.&lt;/strong&gt; The factory refuses any fee above its cap, as the last line of the run shows. The fee rounds down, so the merchant gets any remainder.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A blocked fee never blocks the payout.&lt;/strong&gt; If the fee transfer fails, for example because a stablecoin issuer froze the fee address, the whole amount goes to the merchant and no fee is taken.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;The wrong token is not lost.&lt;/strong&gt; The forwarder can send any token or the native coin it holds, whichever was sent, and always to the same merchant.&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;alert alert-warn&quot;&gt;&lt;strong&gt;One condition stays with the merchant.&lt;/strong&gt; The payout wallet must be a wallet the merchant controls on the network where the payment arrives. A regular wallet controls its address on every EVM network; a smart contract wallet exists only where it was deployed. That is why the dashboard checks the payout address on every network before it is used; the &lt;a href=&quot;https://stablevoy.com/security/&quot;&gt;security page&lt;/a&gt; describes that check.&lt;/div&gt;&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;/h2&gt;&lt;div class=&quot;faq-list&quot;&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Can funds sent to the address before deployment be lost?&lt;/summary&gt;&lt;p&gt;Not on a network where the factory exists. The address is fixed by the factory, the salt and the code, so the forwarder that collects them can only ever be deployed there, bound to the wallet in the salt.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Who pays for the deployment?&lt;/summary&gt;&lt;p&gt;Whoever calls sweep. One transaction deploys the clone and moves the funds, and an invoice that is never paid never costs anything.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Is the address the same on every network?&lt;/summary&gt;&lt;p&gt;Yes, when the factory has the same address on each network, as Stablevoy&apos;s does. A payment sent on the wrong supported network can still be swept, to the same wallet.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Can I check an address myself?&lt;/summary&gt;&lt;p&gt;Yes. Call computeAddress on the factory with the invoice salt, your wallet and the fee from the webhook, or run the function above. The recovery guide walks through sweeping without Stablevoy.&lt;/p&gt;&lt;/details&gt;&lt;/div&gt;</content>
</entry>
<entry>
<id>https://stablevoy.com/blog/safe-mcp-server-payments/</id>
<title>A safe MCP server for a payment API</title>
<link rel="alternate" type="text/html" href="https://stablevoy.com/blog/safe-mcp-server-payments/"/>
<published>2026-11-27T00:00:00Z</published>
<updated>2026-11-27T00:00:00Z</updated>
<summary>What an AI assistant can do with a payment API when a prompt injection gets through, and the design choices that keep the worst case harmless.</summary>
<category term="mcp"/>
<category term="ai"/>
<category term="security"/>
<category term="api"/>
<content type="html">&lt;p&gt;An MCP server lets an AI assistant call a real API: create an invoice, check whether a client paid, sum up the month. It also lets that assistant act on whatever it read last. A web page or a document with hidden instructions can steer it, and the server cannot tell a request from the user from a request planted in a page.&lt;/p&gt;&lt;p&gt;Prompt injection cannot be filtered out reliably, so the design question is what the worst call can do when one gets through. This post walks through how the Stablevoy MCP server answers that, with the parts of the design that make the worst case dull.&lt;/p&gt;&lt;h2 id=&quot;worst-case&quot;&gt;Start from the worst case&lt;/h2&gt;&lt;p&gt;Draw the line between what the server can reach and what it cannot, and make the reachable side harmless on its own.&lt;/p&gt;&lt;figure class=&quot;post-figure&quot;&gt;&lt;img src=&quot;https://stablevoy.com/blog/safe-mcp-server-payments/blast-radius.svg&quot; alt=&quot;A misled assistant calls the MCP server, which holds store keys only. Reachable: create an invoice that pays the merchant, cancel an unpaid invoice, read stores, invoices and totals, search the documentation. Needs the merchant&apos;s wallet in the dashboard: payout address, webhooks, limits, API keys, adding a store. Possible for nobody: moving the money&quot; width=&quot;760&quot; height=&quot;420&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;&lt;figcaption&gt;Nothing a misled assistant can reach moves money or changes where it goes.&lt;/figcaption&gt;&lt;/figure&gt;&lt;p&gt;For a payment gateway the dangerous actions are clear: sending money out, changing where money goes, and handing out new access. None of them is on the left side:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Moving money.&lt;/strong&gt; Stablevoy holds no funds. A payment lands in the merchant&apos;s wallet, directly or through a contract that can only send it there (the&lt;!-- --&gt; &lt;a href=&quot;https://stablevoy.com/security/&quot;&gt;security page&lt;/a&gt; explains how), so there is no balance to withdraw and no API call that sends money anywhere.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Changing where money goes.&lt;/strong&gt; The payout address, the webhooks, the limits and the API keys change only in the dashboard, where the merchant signs in with the wallet, and a new payout address needs a fresh wallet signature on top. The MCP server never holds a dashboard session.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Handing out access.&lt;/strong&gt; Adding a store to the server goes through the browser and the wallet too. The assistant cannot add one.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;What remains on the reachable side is creating invoices that pay the merchant, cancelling an unpaid one, and reading. Each has a cost worth naming:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Reading shows invoice amounts and references to whatever steered the assistant. This is the main exposure.&lt;/li&gt;&lt;li&gt;Cancelling an unpaid invoice tells the buyer not to pay it and sends the shop an &lt;code&gt;invoice.cancelled&lt;/code&gt; webhook, so an open order can be cancelled by mistake. No money is lost, but it is a nuisance.&lt;/li&gt;&lt;li&gt;A created invoice always pays the merchant, and its return page must be on the store&apos;s own website, so a misled assistant cannot send the buyer to a foreign page after paying.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A merchant who connects the server to an assistant that also browses the web should know this, and the next sections give them a way to shrink it further.&lt;/p&gt;&lt;h2 id=&quot;keys&quot;&gt;Give the server the weakest key that works&lt;/h2&gt;&lt;p&gt;The server holds store API keys, nothing else. A store key reaches a short list of endpoints: invoices (create, list, read, cancel, summary), the payment page statistics, the transfers that matched no invoice, and the store&apos;s own settings to read. Every call that changes a setting needs the merchant&apos;s session, and the session lives in the browser.&lt;/p&gt;&lt;p&gt;Each key belongs to one store, and the merchant picks the stores at login. A key is listed on its store page in the dashboard as an MCP key with the name of the computer, and can be revoked there, one by one, without touching the shop&apos;s own keys.&lt;/p&gt;&lt;h2 id=&quot;read-only&quot;&gt;Turn writes off, not down&lt;/h2&gt;&lt;p&gt;Some merchants want the assistant to answer questions and never create anything. The tempting way is to keep the write tools and refuse at call time. The safer way is to not offer them at all, so the model never sees them:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;read-only tool list&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;const storeTools = readOnly ? reads : [...reads, new CreateInvoiceTool(directory), new CancelInvoiceTool(directory)];&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With &lt;code&gt;STABLEVOY_MCP_READ_ONLY=true&lt;/code&gt; in the client config, the server simply has no write tools. Here is the published server, version 0.9.1, started both ways and asked for its tool list over stdio (listing tools needs no key):&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;tool lists of both modes&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;default:   12 tools
read-only: 10 tools
missing in read-only: cancel_invoice create_invoice&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A tool that does not exist cannot be talked into running.&lt;/p&gt;&lt;h2 id=&quot;idempotency&quot;&gt;Make every write safe to repeat&lt;/h2&gt;&lt;p&gt;Models repeat themselves. A timeout, a retry in the client or a second thought, and the same create call arrives twice. For a payment API that means two invoices for one order, and a buyer who may pay both.&lt;/p&gt;&lt;p&gt;Every create call carries an idempotency key built from the store, the amount and the reference:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;idempotency key&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;import { createHash } from &apos;node:crypto&apos;;

const idempotencyKeyOf = (storeId, amount, reference) =&amp;gt;
  `mcp-${createHash(&apos;sha256&apos;).update(JSON.stringify([storeId, amount, reference])).digest(&apos;hex&apos;)}`;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The API returns the invoice it already made for a key it has seen, so &quot;bill Acme 250 dollars for October&quot; asked twice gives one invoice:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;idempotency key output&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;same call twice: same key
another reference: different keys&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The reference is hashed rather than sent as it is, because it may hold anything the model typed and the API accepts printable ASCII only in the key.&lt;/p&gt;&lt;h2 id=&quot;login&quot;&gt;Get the key without copying it&lt;/h2&gt;&lt;p&gt;Pasting an API key into a chat or a config file is how keys end up in screenshots and repositories. The server&apos;s login avoids that.&lt;/p&gt;&lt;figure class=&quot;post-figure&quot;&gt;&lt;img src=&quot;https://stablevoy.com/blog/safe-mcp-server-payments/login.svg&quot; alt=&quot;The command opens the dashboard with a state and a code challenge; the merchant signs with the wallet and ticks stores; the browser hands a one-time code and the state to 127.0.0.1; the command sends the code with its verifier to the API and gets one key per ticked store, saved in a file only the user can read&quot; width=&quot;760&quot; height=&quot;400&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;&lt;figcaption&gt;The key never passes through the browser, the clipboard or the chat.&lt;/figcaption&gt;&lt;/figure&gt;&lt;p&gt;&lt;code&gt;npx stablevoy-mcp login&lt;/code&gt; opens the dashboard in the browser. The merchant signs in with the wallet and ticks the stores. The browser sends a one-time code back to a listener on 127.0.0.1, which checks the state it generated, and the command exchanges the code together with its&lt;!-- --&gt; &lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc7636&quot; rel=&quot;noreferrer&quot;&gt;PKCE&lt;/a&gt; &lt;!-- --&gt;verifier for one key per store. A code caught on the way is useless without the verifier, which never left the computer. The keys are written to a file with mode 0600, in a folder with mode 0700.&lt;/p&gt;&lt;h2 id=&quot;docs&quot;&gt;Read only what you mean to read&lt;/h2&gt;&lt;p&gt;The server also answers questions from the Stablevoy documentation: &quot;how do I verify a webhook in PHP&quot; gets the right section. These tools need no key, which makes them the part most exposed to strange input, so they are fenced in:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;they read only pages of the Stablevoy site, listed in its llms.txt, and refuse any other address;&lt;/li&gt;&lt;li&gt;they follow no redirects;&lt;/li&gt;&lt;li&gt;every request has a 10-second timeout and a 1 MB limit;&lt;/li&gt;&lt;li&gt;every page is kept in memory for an hour, so a chatty assistant does not hammer the site.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A server that fetches any URL the model names is a request forgery tool with a chat interface. This one has no such tool.&lt;/p&gt;&lt;h2 id=&quot;ambiguity&quot;&gt;Ask instead of guessing&lt;/h2&gt;&lt;p&gt;With several stores connected, a call that names no store has two possible meanings, and the server treats reads and writes differently. A read without a store asks every store and labels each answer with its store, so nothing is hidden. Creating an invoice never guesses: &lt;code&gt;create_invoice&lt;/code&gt; without a store, when more than one is connected, comes back with an error that lists the connected stores and tells the model to name one. Cancelling needs no guess either, since only the store that owns the invoice can cancel it. An invoice in the wrong store is a small mistake, but it is the kind that ends with a buyer paying the wrong shop&apos;s link.&lt;/p&gt;&lt;h2 id=&quot;checklist&quot;&gt;A checklist for your own server&lt;/h2&gt;&lt;div class=&quot;table-wrap&quot;&gt;&lt;table class=&quot;table&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Question&lt;/th&gt;&lt;th&gt;What this server does&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;What is the worst call?&lt;/td&gt;&lt;td&gt;Reading invoices, or cancelling an unpaid one. Nothing reachable moves or redirects money.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Which credential does it hold?&lt;/td&gt;&lt;td&gt;Store keys only, one per chosen store, revocable one by one.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Can writes be switched off?&lt;/td&gt;&lt;td&gt;Yes, and then the write tools are not offered at all.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Is every write safe to repeat?&lt;/td&gt;&lt;td&gt;Yes, an idempotency key from store, amount and reference.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;How does the key arrive?&lt;/td&gt;&lt;td&gt;Wallet login in the browser, PKCE and a local listener; never pasted.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;What can it fetch?&lt;/td&gt;&lt;td&gt;Its own documentation pages only, no redirects, with time and size limits.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;What happens when a call is ambiguous?&lt;/td&gt;&lt;td&gt;A read asks every store; creating an invoice asks for the store instead of picking one.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;The server is open source on&lt;!-- --&gt; &lt;a href=&quot;https://github.com/stablevoy/stablevoy-mcp&quot; rel=&quot;noreferrer&quot;&gt;GitHub&lt;/a&gt;, and the &lt;a href=&quot;https://stablevoy.com/mcp/&quot;&gt;MCP page&lt;/a&gt; shows how to connect it to Claude, Cursor or any other client. The &lt;a href=&quot;https://stablevoy.com/docs/sdks/&quot;&gt;SDK page&lt;/a&gt; covers the libraries for the same API.&lt;/p&gt;&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;/h2&gt;&lt;div class=&quot;faq-list&quot;&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Can a prompt injection make the assistant send money?&lt;/summary&gt;&lt;p&gt;No. Neither the server nor the API it uses has a call that sends money; payments land in the merchant&apos;s own wallet.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Can it change my payout wallet?&lt;/summary&gt;&lt;p&gt;No. That needs a fresh signature from your wallet in the dashboard, which the server cannot produce.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;What is the most it can do with a store key?&lt;/summary&gt;&lt;p&gt;Create invoices that pay you, cancel an unpaid one, and read your invoices and totals. Run it read-only to remove the first two.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;How do I take access away?&lt;/summary&gt;&lt;p&gt;Revoke the key on the store page of the dashboard, or run npx stablevoy-mcp logout to revoke every key of that computer.&lt;/p&gt;&lt;/details&gt;&lt;/div&gt;</content>
</entry>
<entry>
<id>https://stablevoy.com/blog/verify-webhook-signatures/</id>
<title>How to verify webhook HMAC signatures in PHP and Node.js</title>
<link rel="alternate" type="text/html" href="https://stablevoy.com/blog/verify-webhook-signatures/"/>
<published>2026-11-27T00:00:00Z</published>
<updated>2026-11-27T00:00:00Z</updated>
<summary>A webhook is only as safe as its signature check. Build one in PHP and Node.js: raw body, HMAC-SHA256, constant-time compare, replay window, retries.</summary>
<category term="webhooks"/>
<category term="php"/>
<category term="node"/>
<category term="security"/>
<content type="html">&lt;p&gt;A webhook endpoint is a public URL that changes orders. Anyone who finds it can send it a request that says &quot;invoice paid&quot;, so the only thing standing between a forged request and a shipped order is the signature check. This post builds that check in PHP and in Node.js, step by step, and runs it against a valid request, a forged one and a replayed one.&lt;/p&gt;&lt;p&gt;The examples use the Stablevoy header format, &lt;code&gt;X-Stablevoy-Signature: t=&amp;lt;unix seconds&amp;gt;,v1=&amp;lt;hex&amp;gt;&lt;/code&gt;. Many payment providers sign webhooks the same way and differ only in the header name and the encoding, so the code carries over with small changes.&lt;/p&gt;&lt;h2 id=&quot;delivery&quot;&gt;How a signed delivery works&lt;/h2&gt;&lt;p&gt;The sender and your server share one secret. The sender never sends it: it uses the secret to compute an HMAC of the request and puts the result in a header. Your server computes the same HMAC from what it received. If the two match, the request came from someone who knows the secret and nobody changed it on the way.&lt;/p&gt;&lt;figure class=&quot;post-figure&quot;&gt;&lt;img src=&quot;https://stablevoy.com/blog/verify-webhook-signatures/delivery.svg&quot; alt=&quot;Stablevoy signs the event and posts it with the signature and event id headers; your server checks it and answers 200 within 10 seconds; without a 2xx in time the delivery is retried with growing pauses for about a day&quot; width=&quot;760&quot; height=&quot;340&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;&lt;figcaption&gt;One delivery. A request without a 2xx answer in time is sent again, so the same event can arrive more than once.&lt;/figcaption&gt;&lt;/figure&gt;&lt;p&gt;Two things follow from this picture. A valid signature says who sent the request, not when, so an old request recorded by someone in the middle would still pass on its own. And retries mean one event can reach you several times. The check below handles both.&lt;/p&gt;&lt;h2 id=&quot;signed-string&quot;&gt;What exactly gets signed&lt;/h2&gt;&lt;p&gt;The signed string is the timestamp, a dot and the raw request body. The timestamp is inside the signed string, so it cannot be changed without breaking the signature.&lt;/p&gt;&lt;figure class=&quot;post-figure&quot;&gt;&lt;img src=&quot;https://stablevoy.com/blog/verify-webhook-signatures/signed-string.svg&quot; alt=&quot;The timestamp 1795776000, a dot and the raw JSON body are joined into one string, hashed with HMAC-SHA256 using the signing secret, and the hex result goes into the header as v1&quot; width=&quot;760&quot; height=&quot;300&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;&lt;figcaption&gt;The v1 value is HMAC-SHA256 of &quot;t.body&quot; with your signing secret, written as 64 hex characters.&lt;/figcaption&gt;&lt;/figure&gt;&lt;p&gt;&quot;Raw body&quot; means the bytes exactly as they arrived. If your framework parses the JSON first and you encode it again, the keys may come out in another order, a slash may get escaped, a number may lose a trailing zero, and the HMAC no longer matches even though the data is the same. Read the body before anything touches it.&lt;/p&gt;&lt;h2 id=&quot;php&quot;&gt;Verify in PHP&lt;/h2&gt;&lt;p&gt;PHP has everything built in: &lt;code&gt;hash_hmac&lt;/code&gt; for the signature (&lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc2104&quot; rel=&quot;noreferrer&quot;&gt;HMAC is defined in RFC 2104&lt;/a&gt;) and&lt;!-- --&gt; &lt;a href=&quot;https://www.php.net/manual/en/function.hash-equals.php&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;hash_equals&lt;/code&gt;&lt;/a&gt; &lt;!-- --&gt;for a comparison that takes the same time whether the first or the last character differs. A plain &lt;code&gt;===&lt;/code&gt; stops at the first wrong character, and that difference in time can be measured over many requests.&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;PHP signature check&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&amp;lt;?php
declare(strict_types=1);

// Checks X-Stablevoy-Signature: t=&amp;lt;unix seconds&amp;gt;,v1=&amp;lt;hex HMAC-SHA256 of &quot;&amp;lt;t&amp;gt;.&amp;lt;raw body&amp;gt;&quot;&amp;gt;.
function verify_webhook(string $rawBody, string $header, string $secret, int $tolerance = 300, ?int $now = null): bool
{
    $timestamp = null;
    $signatures = [];
    foreach (explode(&apos;,&apos;, $header) as $part) {
        [$key, $value] = array_pad(explode(&apos;=&apos;, trim($part), 2), 2, &apos;&apos;);
        if ($key === &apos;t&apos; &amp;amp;&amp;amp; ctype_digit($value)) {
            $timestamp = (int) $value;
        } elseif ($key === &apos;v1&apos; &amp;amp;&amp;amp; $value !== &apos;&apos;) {
            $signatures[] = $value;
        }
    }
    if ($timestamp === null || $signatures === []) {
        return false; // malformed header
    }
    if (abs(($now ?? time()) - $timestamp) &amp;gt; $tolerance) {
        return false; // too old or from the future: a replay, or a wrong clock
    }
    $expected = hash_hmac(&apos;sha256&apos;, $timestamp . &apos;.&apos; . $rawBody, $secret);
    foreach ($signatures as $signature) {
        if (hash_equals($expected, $signature)) {
            return true;
        }
    }
    return false;
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Three details matter here:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;The parser accepts more than one &lt;code&gt;v1&lt;/code&gt; value. Stablevoy sends one, but the format allows several, and a sender that signs with an old and a new secret during a rotation would otherwise be refused.&lt;/li&gt;&lt;li&gt;The five-minute window (&lt;code&gt;$tolerance = 300&lt;/code&gt;) is what stops a replay: a recorded request is rejected once it is older than that. Keep the server clock in sync with NTP, or valid requests start failing too.&lt;/li&gt;&lt;li&gt;The body comes from &lt;code&gt;php://input&lt;/code&gt;, never from &lt;code&gt;$_POST&lt;/code&gt;, which is empty for a JSON request anyway.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;In the endpoint it looks like this:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;PHP webhook endpoint&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;$secret = getenv(&apos;STABLEVOY_WEBHOOK_SECRET&apos;) ?: throw new RuntimeException(&apos;STABLEVOY_WEBHOOK_SECRET is not set&apos;);
$rawBody = file_get_contents(&apos;php://input&apos;); // the exact bytes, not $_POST
$header = $_SERVER[&apos;HTTP_X_STABLEVOY_SIGNATURE&apos;] ?? &apos;&apos;;

if (!verify_webhook($rawBody, $header, $secret)) {
    http_response_code(400);
    exit;
}
$event = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The secret lives in the environment, not in the code. If it is missing, the script stops with an error instead of checking against an empty string.&lt;/p&gt;&lt;div class=&quot;alert alert-warn&quot;&gt;&lt;strong&gt;Mark an order paid only from a verified webhook.&lt;/strong&gt; The page the buyer returns to after paying proves nothing: anyone can open that address by hand.&lt;/div&gt;&lt;h2 id=&quot;node&quot;&gt;Verify in Node.js&lt;/h2&gt;&lt;p&gt;In Node.js the same check uses &lt;code&gt;createHmac&lt;/code&gt; and&lt;!-- --&gt; &lt;a href=&quot;https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;timingSafeEqual&lt;/code&gt;&lt;/a&gt; &lt;!-- --&gt;from &lt;code&gt;node:crypto&lt;/code&gt;. &lt;code&gt;timingSafeEqual&lt;/code&gt; throws when the two buffers differ in length, so the header value is checked to be 64 hex characters before it becomes a buffer.&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Node.js signature check&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;import { createHmac, timingSafeEqual } from &apos;node:crypto&apos;;

// rawBody is a Buffer with the exact bytes received, before any JSON parsing.
export function verifyWebhook(rawBody, header, secret, { tolerance = 300, now = Date.now() / 1000 } = {}) {
  let timestamp = null;
  const signatures = [];
  for (const part of (header ?? &apos;&apos;).split(&apos;,&apos;)) {
    const [key, value = &apos;&apos;] = part.trim().split(&apos;=&apos;, 2);
    if (key === &apos;t&apos; &amp;amp;&amp;amp; /^\d+$/.test(value)) timestamp = Number(value);
    else if (key === &apos;v1&apos; &amp;amp;&amp;amp; /^[0-9a-f]{64}$/.test(value)) signatures.push(Buffer.from(value, &apos;hex&apos;));
  }
  if (timestamp === null || signatures.length === 0) return false; // malformed header
  if (Math.abs(now - timestamp) &amp;gt; tolerance) return false; // too old or from the future
  const expected = createHmac(&apos;sha256&apos;, secret).update(`${timestamp}.`).update(rawBody).digest();
  return signatures.some((given) =&amp;gt; timingSafeEqual(given, expected));
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The raw body is where Node.js setups usually go wrong. &lt;code&gt;express.json()&lt;/code&gt; reads the stream and hands you a parsed object, and the original bytes are gone. Mount the webhook route with &lt;code&gt;express.raw({ type: &apos;application/json&apos; })&lt;/code&gt; instead, so &lt;code&gt;req.body&lt;/code&gt; is a Buffer, or read the stream yourself:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Node.js raw body&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;// inside the request handler
const chunks = [];
let size = 0;
for await (const chunk of req) {
  size += chunk.length;
  if (size &amp;gt; 64 * 1024) return res.writeHead(413).end(); // a webhook is small; refuse anything large
  chunks.push(chunk);
}
const rawBody = Buffer.concat(chunks);
if (!verifyWebhook(rawBody, req.headers[&apos;x-stablevoy-signature&apos;], secret)) return res.writeHead(400).end();
const event = JSON.parse(rawBody.toString(&apos;utf8&apos;));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;run&quot;&gt;Run it against four requests&lt;/h2&gt;&lt;p&gt;Both versions were run on one body signed the way the sender signs it, then on three requests that must fail: the same signature over a changed body, the original request ten minutes later, and a signature made with another secret.&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;output of both checks&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;$ php verify.php
valid                  accepted
body changed           rejected
replayed after 10 min  rejected
wrong secret           rejected

$ node verify.mjs
valid                  accepted
body changed           rejected
replayed after 10 min  rejected
wrong secret           rejected&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The PHP run used PHP 8.3, the Node.js run Node.js 22 and 26 with the same result. For the same secret, time and body both produce the signature&lt;!-- --&gt; &lt;code&gt;ff2448e5...f6e35b3c&lt;/code&gt;, which is also what the Stablevoy sender computes, so a request signed by one side passes the check of the other.&lt;/p&gt;&lt;h2 id=&quot;retries&quot;&gt;Handle each event once&lt;/h2&gt;&lt;p&gt;Verification answers &quot;is this request genuine&quot;. The next question is &quot;have I already handled it&quot;, because a delivery is retried until your server answers 2xx in time, and an answer that got lost on the way back looks like a failure to the sender.&lt;/p&gt;&lt;figure class=&quot;post-figure&quot;&gt;&lt;img src=&quot;https://stablevoy.com/blog/verify-webhook-signatures/checks.svg&quot; alt=&quot;The checks in order: read the raw body, parse t and v1, check the five-minute window, compare the HMAC, look up the event id; a malformed, old or unmatched request gets 400 and changes nothing, a known event id gets 200 without processing, a new one is processed and gets 200&quot; width=&quot;760&quot; height=&quot;470&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;&lt;figcaption&gt;Every failure has one answer. A duplicate is not an error: answer 200 so the retries stop.&lt;/figcaption&gt;&lt;/figure&gt;&lt;p&gt;Every delivery carries the event id in &lt;code&gt;X-Stablevoy-Event-Id&lt;/code&gt;. Store it under a unique key in the same transaction that marks the order paid, and let the database refuse the second copy:&lt;/p&gt;&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;PHP handling each event once&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;$eventId = $_SERVER[&apos;HTTP_X_STABLEVOY_EVENT_ID&apos;] ?? $event[&apos;id&apos;];

$pdo-&amp;gt;beginTransaction();
try {
    // processed_events.event_id is the primary key: the second delivery of the same event fails here.
    $pdo-&amp;gt;prepare(&apos;INSERT INTO processed_events (event_id, type) VALUES (?, ?)&apos;)-&amp;gt;execute([$eventId, $event[&apos;type&apos;]]);
} catch (PDOException $e) {
    $pdo-&amp;gt;rollBack();
    // SQLSTATE class 23 is a constraint violation: 23000 on MySQL and SQLite, 23505 on PostgreSQL.
    if (str_starts_with((string) $e-&amp;gt;getCode(), &apos;23&apos;)) {
        http_response_code(200); // already handled: answer 2xx so the retries stop
        exit;
    }
    throw $e;
}

// ... mark the order paid here, with the same $pdo

$pdo-&amp;gt;commit();
http_response_code(200);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The order of the steps is the point. The event id and the order change are saved together or not at all: if the order update throws, the transaction is rolled back, the endpoint answers 500, and the next retry handles the event from the start. Only the insert sits inside the &lt;code&gt;try&lt;/code&gt;, so an error in the order update is never mistaken for a duplicate.&lt;/p&gt;&lt;p&gt;A check like &lt;code&gt;SELECT ... then INSERT&lt;/code&gt; leaves a gap where two parallel retries both see &quot;not yet&quot; and both ship the order. The unique key closes that gap.&lt;/p&gt;&lt;p&gt;Against a local server with this code, the first delivery got 200, the same event sent again got 200 with still one row in &lt;code&gt;processed_events&lt;/code&gt;, a forged body got 400 and a request without the header got 400. With an order update that throws, both deliveries got 500 and the table stayed empty, which is what lets the retry succeed later.&lt;/p&gt;&lt;p&gt;Answer fast. Stablevoy waits 10 seconds for an answer and treats a slower one as failed, so do the heavy work (emails, stock updates, calls to other services) after the event is saved, or in a queue.&lt;/p&gt;&lt;h2 id=&quot;mistakes&quot;&gt;Mistakes that break the check&lt;/h2&gt;&lt;div class=&quot;table-wrap&quot;&gt;&lt;table class=&quot;table&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Mistake&lt;/th&gt;&lt;th&gt;What happens&lt;/th&gt;&lt;th&gt;Fix&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;JSON parsed before the check&lt;/td&gt;&lt;td&gt;The bytes change, valid requests fail&lt;/td&gt;&lt;td&gt;Verify the raw body, parse after&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code&gt;==&lt;/code&gt; or &lt;code&gt;===&lt;/code&gt; on the signature&lt;/td&gt;&lt;td&gt;The comparison leaks timing&lt;/td&gt;&lt;td&gt;&lt;code&gt;hash_equals&lt;/code&gt; in PHP, &lt;code&gt;timingSafeEqual&lt;/code&gt; in Node.js&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;No time window&lt;/td&gt;&lt;td&gt;A recorded request stays valid forever&lt;/td&gt;&lt;td&gt;Refuse a &lt;code&gt;t&lt;/code&gt; older than five minutes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;The secret in the code or the repository&lt;/td&gt;&lt;td&gt;Anyone who reads the repository can forge events&lt;/td&gt;&lt;td&gt;Keep it in the environment, and rotate it in the dashboard if it leaks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;500 for a duplicate&lt;/td&gt;&lt;td&gt;The sender retries it again and again&lt;/td&gt;&lt;td&gt;A known event id gets 200&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;A redirect or plain HTTP in front&lt;/td&gt;&lt;td&gt;The delivery fails&lt;/td&gt;&lt;td&gt;Point the webhook at the final &lt;code&gt;https&lt;/code&gt; address on port 443&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;h2 id=&quot;sdk&quot;&gt;Or let the SDK do it&lt;/h2&gt;&lt;p&gt;The Stablevoy SDKs for PHP, Node.js and Python include a verifier that does all of the above and returns the parsed event, or throws with a message that says what was wrong: a missing header, an old timestamp or a body that does not match. The &lt;a href=&quot;https://stablevoy.com/docs/sdks/&quot;&gt;SDK page&lt;/a&gt; shows how to install them, and the&lt;!-- --&gt; &lt;a href=&quot;https://stablevoy.com/docs/webhooks/&quot;&gt;webhooks documentation&lt;/a&gt; lists every event, how retries work and the delivery rules. How the payments behind these events stay bound to your own wallet is on the &lt;a href=&quot;https://stablevoy.com/security/&quot;&gt;security page&lt;/a&gt;.&lt;/p&gt;&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;/h2&gt;&lt;div class=&quot;faq-list&quot;&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Why does my signature never match even with the right secret?&lt;/summary&gt;&lt;p&gt;Almost always the body was parsed and encoded again before the check. Compute the HMAC over the raw bytes the server received, and make sure the string is the timestamp, a dot and the body, in that order.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Is a five-minute window too short?&lt;/summary&gt;&lt;p&gt;No, as long as the server clock is synced. Deliveries are signed when they are sent, retries included, so a valid request is seconds old when it arrives.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;Do I still need the signature if the endpoint URL is secret?&lt;/summary&gt;&lt;p&gt;Yes. URLs end up in logs, browser histories and error trackers. The signature is the only part an attacker cannot copy without the secret.&lt;/p&gt;&lt;/details&gt;&lt;details class=&quot;faq-item&quot;&gt;&lt;summary&gt;What should the endpoint answer to a request that fails the check?&lt;/summary&gt;&lt;p&gt;A 400 with no details, and no change to any order. Log it on your side if you want to see who is probing the endpoint.&lt;/p&gt;&lt;/details&gt;&lt;/div&gt;</content>
</entry>
</feed>
