Short answer
A price config tells your server what to charge, so a forged one is a forged price. Leverprice signs configs through a chain modeled on TUF: an offline root key signs a keyset of online keys, which sign configs that expire and only move forward in version. Your own min, max and currency checks still have the last word.
- The root private key stays offline and signs only keysets, so rotating or revoking an online signing key needs no SDK release.
- Config and keyset versions only move forward, and every config expires 72 hours after it is signed.
- Each config lists fingerprints of the project's API keys, so a validly signed config for another project is refused even on first load.
- If no usable config arrives within 500 ms, getPrice() returns your fallbackPrice and never throws.
- Owner actions reach the edge in about a second through a global cache purge; config delivery moved off Workers KV to get there.
If your server creates the checkout, the worst a fully compromised Leverprice can do to it is pick a price between the minPrice and maxPrice written in your code, in the currency written there. Any other price sends the visitor to your own fallbackPrice. The signing chain below exists so that anything short of a full compromise, such as a hostile network or a tampered cache, can't get even that far.
A config is the signed JSON document that tells our SDK which prices a product has, which experiment is running and how traffic is split. Our engine signs it, and the SDK on your server verifies it before returning any price. The edge in between holds no signing key, so anything it alters fails verification. No Leverprice code runs in the visitor's browser; why we test prices server-side explains that choice.
What could a tampered config do to your checkout?
It could change what your customers pay. The SDK treats the config as the source of prices, so whoever controls the config controls the number your server hands to Stripe or Polar. We listed everyone who could get that control and what stops each of them.
| Who | What they would try | What stops them |
|---|---|---|
| Someone on the network path, including a proxy that terminates TLS | Edit a config in transit | Ed25519 signatures that the SDK checks itself |
| An attacker inside our edge or its cache | Serve a forged config, or an old one | The edge holds no signing key; versions only move forward; configs expire |
| An attacker with access to our database | Rewrite a stored config | Signing keys never live in the database, so a rewritten config fails verification |
| A thief of an online signing key | Sign a malicious config | A new keyset revokes the key without an SDK release; prices stay inside your bounds |
| Someone holding a valid config from another project | Serve it to your server | Each config names the API keys it was issued for |
| Our own bug | Sign a config with a wrong price | Your local min, max and currency checks |
Two things sit outside this model. If an attacker controls the process that calls getPrice(), they don't need us. And in no-code mode the Buy button points at a Leverprice link that redirects to your checkout, so there you trust our redirect as well as our prices. Fake revenue is a separate problem with its own defenses, covered in counting revenue you can trust.
How does the signing chain work?
Each layer is signed by a different key, and each key is used as rarely as its job allows.
The root key pair is Ed25519. Its private half is kept offline and never touches Cloudflare. Its public half is compiled into every SDK as ROOT_PUBLIC_KEYS. The root key signs one kind of document: a keyset.
A keyset is a short list of online public keys, with a version number and an optional expiry. To rotate or revoke an online key, we sign a new keyset with a higher version. That needs no SDK release and no action from customers.
The config itself is signed by an online key held by one worker, the engine, which has no public routes. The engine is also the only holder of the token that purges our cache. The edge, the worker that faces the internet, holds neither. Every config travels with the keyset that vouches for its key, so the SDK can check the whole chain from a single response.
Signatures cover the base64url payload string exactly as it travels, not the decoded JSON. JWS works the same way (RFC 7515, section 2), while TUF signs a canonical form of its metadata (TUF specification). Signing the transported string means none of our five SDKs ever has to re-serialize JSON byte for byte before it can check a signature.
When a config arrives, the SDK accepts it only if every step passes:
- The keyset is signed by a root key the SDK already trusts.
- The keyset has not expired, its version is at least the SDK's built-in minimum, and it is not older than the newest keyset this process has seen.
- The config's signing key is listed in that keyset, and the config signature verifies with it.
- The config has not expired.
- The config lists the fingerprint of this server's own API key.
- If the process already holds a config, the new one belongs to the same project and has an equal or higher version.
A malformed key or signature counts as "not verified", never as a crash. A product that fails to parse is dropped and reported, and the rest of the config is still used. A config whose signing key has dropped out of the newest keyset stops being usable, even if the process loaded it before the revocation.
What did we take from TUF and DNSSEC?
Most of the design. The Update Framework (TUF) is a CNCF graduated project for securing software update systems, built to protect clients even when the repository or its signing keys are compromised (TUF). A price config is a small software update that arrives every few minutes, so the comparison fits. The TUF specification lists the attacks it is designed to stop (TUF specification), and four of them map directly onto prices:
| Attack in TUF's list | What it would mean for prices | Our answer |
|---|---|---|
| Key compromise | A leaked signing key mints configs | Offline root key; online keys revoked by a new keyset |
| Indefinite freeze | An attacker keeps replaying an old config and you never notice | Configs expire 72 hours after signing and are re-signed daily |
| Rollback | An older config, with older prices, comes back | Versions only move forward, in our database and in the SDK |
| Mix-and-match | Pieces of different configs get combined | One signed document per project, bound to that project's API keys |
The root key follows TUF's rule that the root role's private keys should be kept offline (TUF specification).
DNSSEC splits its keys the same way. A key-signing key (KSK) signs only the zone's DNSKEY set, zone-signing keys (ZSKs) sign everything else, and the split exists so the KSK can be stored offline while ZSKs stay available and roll often (RFC 6781, section 3.1). At the DNS root, IANA usually holds key ceremonies four times a year, where the KSK signs the operational ZSKs for a three-month period (IANA). In our chain the root key plays the KSK, the keyset plays the DNSKEY set and the online key plays the ZSK.
Some of TUF we left out. TUF lets a role require a threshold of signatures from several keys; we have one root key and one signature per layer. TUF rotates its root by having each root version sign the next; our root public key is compiled into the SDKs, so replacing it means shipping five SDK releases.
TUF clients keep trusted metadata between runs. Our SDKs keep the newest keyset version only in memory, except PHP, which stores it in APCu or a file cache because every PHP request starts from scratch. A freshly started process relies on MIN_KEYSET_VERSION, the floor compiled into the SDK, and on config expiry.
Which TUF rule did we break?
One. TUF's goals say keys used in an automated fashion must not sign anything clients ultimately trust for what they install (TUF specification). In TUF, the keys meant to stay online belong to roles like timestamp, which signs freshness statements rather than the files clients install.
We can't follow that rule. The multi-armed bandit behind Leverprice recomputes traffic weights every five minutes and signs the result. Lock in, pause, stop and range edits publish within about a second. Nobody can do that with a key kept in a safe, so the document your SDK acts on is signed online.
The compensating control is your code. Before getPrice() returns a price, the SDK checks that:
- the price is a positive integer in minor units;
- it is at least the larger of your
minPriceand the config's own minimum, and at most the smaller of yourmaxPriceand the config's maximum; - the config's currency equals the currency in your code;
- a regional price is served only in a currency you listed under
regional, inside the bounds you set for that currency.
If any variant of a running experiment falls outside those bounds, the SDK serves your fallbackPrice for that product, whichever variant the visitor drew. It doesn't try to salvage the good variants.
import { Leverprice } from "@leverprice/sdk";
export const leverprice = new Leverprice({
secretKey: process.env.LEVERPRICE_SECRET_KEY,
products: {
// Only USD prices from $19 to $49 can ever reach the checkout.
pro: { currency: "usd", fallbackPrice: 2900, minPrice: 1900, maxPrice: 4900 },
},
});So a stolen online key, plus some way to deliver configs to your server, lets an attacker choose among prices you already accepted, until a new keyset revokes the key. That is why a tight range matters. With a $19 to $49 guard on a $29 product, the worst case is a price you considered reasonable when you wrote the line.
How do old configs and revoked keys stay dead?
Versions only move forward on both ends of the wire, and every config expires.
On our side, the signed config is stored in D1 (published_configs) with a conditional upsert, so the stored version never decreases, even when two publishers race. On your side, the SDK refuses any config older than the one it holds and reports that it refused to roll back.
Keysets work the same way. The SDK remembers the highest keyset version it has verified and rejects anything older, so an attacker can't bring a revoked key back by replaying an old keyset next to an old config.
Versions stop rollback. They do nothing against a freeze, where an attacker keeps serving the newest config they captured.
The SDK revalidates every 30 seconds with an ETag, and an unchanged config comes back as a 304 with no body. A 304 carries no signature, so it proves only that something answered. The signed bound is the expiry: configs live 72 hours and are re-signed daily. Separately, by default the SDK stops using a config 24 hours after our server last confirmed it.
That arithmetic cuts both ways. Daily re-signing with a 72-hour lifetime means our signing pipeline can stall for about two days before any config expires. It also means a captured config could be replayed to a freshly started process for up to 72 hours after it was signed, by someone able to deliver it to your server.
Why does a config carry fingerprints of your API keys?
A signature proves that we issued a config. On its own, it says nothing about which customer we issued it for.
So the signed body also lists the first 16 hex characters of the SHA-256 of every active API key in the project. The SDK hashes its own secret key and refuses any config whose list lacks it, including on the very first load, when there is no earlier project to compare against. A validly signed config for someone else's project fails that check. After the first load, the SDK also pins the project id and refuses configs for any other project.
Revocation uses the same list. Configs published after a key is revoked no longer carry its fingerprint, and our edge refuses the key itself, so a process still running with that key keeps its last good config only until that config goes stale.
What happens if Leverprice is down or sends a bad price?
Your visitors get the price you wrote in code. getPrice() never throws because of us. The only exception it raises is for a product key you never configured, which is a bug in your code.
With a usable config, nothing on the request path touches the network. Assignment is an HMAC and a SHA-256 bucket computed on your server, and refreshes start in the background, triggered by traffic.
The 500 ms budget applies only when a process has no usable config: on a cold start, or after its config expired. Requests then wait for the in-flight fetch, but never longer than 500 ms from the moment that fetch started, so every request that piles up during a cold start gives up at the same instant. After a failed fetch the SDK backs off, from 1 second doubling up to 30, and returns your fallback immediately while it waits.
A visitor who got your fallback during an outage keeps it. Visitors normally keep their price through a signed cookie (sticky assignment), and an outage adds a second one: the quote sets __pp_f for 30 minutes, renewed on every pinned request, so nobody sees $29 and then $39 on a reload. That cookie is unsigned on purpose, because the only thing it can select is your own fallback price.
LEVERPRICE_DISABLED=1 is read on every call. While it is set, the SDK returns your fallback, sets no cookies, makes no network calls and logs nothing. Every fallback quote carries a reason (no_config, pinned_fallback, out_of_bounds, currency_mismatch, unknown_product or disabled), so you can log why a visitor got your price.
Why did we drop Workers KV?
Because with KV we couldn't put a bound on how long a revoked key keeps working.
Our first version wrote every change twice, to D1 and to Workers KV, and served configs from KV. KV is eventually consistent: Cloudflare's documentation says a change can take 60 seconds or more to become visible in other locations (Cloudflare). The dual write was worse: when a KV delete failed, a revoked API key could keep working indefinitely.
Now D1 holds the only copy. The edge reads it through the Cache API of its own data center, about a millisecond on a hit. Cache API contents never replicate outside the data center that stored them (Cloudflare), and a cached config lives at most 30 seconds. That TTL is the ceiling on staleness even if a purge goes missing.
When an owner acts (stop, pause, Lock in, a range edit, a key revocation), the engine purges by cache tag across the whole network. Cloudflare reports a median under 150 ms for tag purges (Cloudflare) and has offered them on every plan since April 2025 (Cloudflare).
A purge can't reach an isolate's memory, where the edge also keeps API key lookups, so that memo lives at most 1 second. We measured the difference on our staging environment on November 17, 2026: with a 10-second memo, a deleted project's key was still accepted for 5.8 seconds; with a 1-second memo, it was refused after 0.17 seconds.
The guarantees we ended up with: a revoked key stops working in about a second, and in 60 seconds at most while D1 is healthy. If D1 is down, the edge keeps serving the last copy it has, so pricing doesn't fail along with the database. In that case only, a cached key record can outlive a revocation by up to 10 minutes. A rate limit never extends a key's life, since an attacker could trigger one on purpose.
Purge limits are counted per account (Cloudflare), so the five-minute bandit updates don't purge at all; the 30-second TTL picks them up. Every response to POST /v1/events also carries the current version in a Leverprice-Config-Version header, so a server that is sending events learns about a stop or a Lock in at its next flush instead of waiting for the 30-second poll.
What does all of this cost?
Some of it you pay, some of it we pay.
| Cost | Who pays | How much |
|---|---|---|
| First config on a cold process | Serverless functions, new containers | Up to 500 ms on the first requests; preload() moves the fetch to startup on long-lived servers |
| Signature checks | Your server | One Ed25519 verification per new config body; an unchanged config is a bodyless 304, and verified keysets are cached |
| Background refresh | A visitor right after an idle period | The first request after idling can still use the previous config while the refresh runs |
| Expiry | You, during a long outage of ours | After 24 hours without a confirmation, or 72 hours after signing, you serve your fallback price |
| Root key rotation | Us | Five SDK releases, because the root public key is compiled in |
| Keyset changes | Us | Signed offline, by hand |
| Five SDKs agreeing byte for byte | Us | Conformance vectors generated from server code, plus a contract test that runs the real SDK against server-signed configs, rotation and revocation included |
Python without the cryptography package falls back to a pure-Python Ed25519 verifier that ships with the SDK. It is slow, but it only runs when a new config body arrives.
One check we kept while knowing its limits: our edge answers 403 to any request that carries an Origin header. It catches developers who paste a secret key into browser code. Outside a browser anyone can send any Origin, so authentication rests on the secret key alone.
A checklist if you ship signed config to other people's servers
- Keep the most powerful key offline and let it sign keys, never data.
- Sign the bytes you transport, so no client has to re-serialize JSON before verifying.
- Put a version in everything you sign and refuse to go backwards, both where you write and where you verify.
- Put an expiry in everything you sign, and treat unsigned freshness, such as a 304, as a hint.
- Name the tenant inside the signed body.
- Let the customer's own code hold limits your server can't override.
- Fail to the customer's own value within a fixed time budget, and never throw because of your outage.
- Keep one source of truth, and give every cache a TTL that bounds staleness when a purge goes missing.
If you use Leverprice, the installation docs show where the guard and the fallback live in your code, and the security page covers what we store and how.
Frequently asked questions
Why Ed25519 signatures instead of an HMAC?
Anyone who can check an HMAC can also produce one, so every server able to verify configs, our internet-facing edge included, could also mint them. With Ed25519 (RFC 8032) the SDK holds only public keys, and private signing keys live only in a worker with no public routes.
Can I test the SDK against my own root key?
Yes. For local development and staging, pass trustedRootKeys: { r1: "<your dev root public key>" }. By default the SDK trusts only Leverprice's root public keys.
What happens to my prices if Leverprice is down for a whole day?
A running server keeps its last config until 24 hours pass without a confirmation from us, then serves your fallbackPrice. A process that starts during the outage waits at most 500 ms on its first request and serves your fallback from then on.
Is anything secret inside a config?
One thing: your project's assignment key, which signs visitor cookies and checkout attribution. Only requests authenticated with your project's secret key receive it. Signatures protect integrity; confidentiality comes from TLS and from keeping the secret key on your server.
Can a visitor change the price they get?
No. The assignment cookie is HMAC-signed with that assignment key, and the price is computed on your server from the signed config. A cookie that fails verification is ignored, and the visitor is assigned as if new.