← Back to the blog

Security • 2026-09-17 • 3 min read

Signing API Requests with Ed25519: Replay Windows and Key Rotation

A bearer token proves possession. A signature proves the request was not altered on the way. What we put in the signing string, and the two mistakes that make it decorative.

Signing API Requests with Ed25519: Replay Windows and Key Rotation — Security

A bearer token says "whoever holds this is allowed". A signature says "this exact request, from this client, at this time". The second is worth the extra work on anything that moves money, changes permissions or cannot be replayed safely.

What the signature covers

Getting the signing string wrong is the most common failure, and it fails silently — everything works, and the protection is not there.

The string must include:

  • The HTTP method, or a signed GET can be replayed as a DELETE on the same path
  • The full path and the query string, canonicalised
  • A hash of the body, not the body itself, so large uploads do not need buffering twice
  • A timestamp
  • A nonce
  • The key id, so the server knows which key to verify against without guessing
// text
POST
/v1/transfers
amount=100&currency=EUR
sha256=3b0c44298fc1c149afbf4c8996fb924...
1764633600
01J9Z7K4N2Q8

Join with a separator that cannot appear in any field — a newline, with every field length-prefixed or strictly validated. Concatenating with commas invites a splitting attack where moving a character between two fields produces the same string.

The replay window

The timestamp bounds how long a captured request stays useful. Five minutes is the usual figure, and it is a trade-off against clock skew: too tight and honest clients fail, too loose and a captured request is reusable for longer than you would like.

The nonce is what makes the window actually close. Store each nonce until its timestamp falls outside the window and reject repeats — Redis with a TTL is the obvious implementation. Without the nonce store, the window is not a replay defence; it is a time limit on replay.

Rotation without an outage

Clients cannot all switch keys at the same instant, so the server has to accept both for a period.

  1. Issue the new key and publish it alongside the old one; the server accepts either, selected by the key_id in the request
  2. Clients move over at their own pace
  3. Watch usage per key id until the old one is unused
  4. Remove it, and alert if anything still presents it

The key_id in the signing string is what makes this possible. A protocol with one implicit key has no migration path, which in practice means the key is never rotated.

Two mistakes worth naming

Verifying the signature after parsing the body. The signature exists to tell you whether the body can be trusted; parsing megabytes of JSON before checking is doing the expensive thing on behalf of an unauthenticated caller. Hash the raw bytes, verify, then parse.

Comparing with `==`. Use a constant-time comparison for anything secret-derived. The libraries do this internally for signatures; your own code around them often does not.

The verification side and its latency budget are in the Security API design notes.

Read next

COOKIES // MEASUREMENT

We count page views through Google Tag Manager. Say yes and it may store a cookie in your browser; say no and it still counts the visit, without storing anything and without an identifier. Nothing here is used for advertising.

Cookie Policy — you can change this at any time from the footer of any page.