design and build a challenge that survives a solver · lesson 4 of 7 · sources checked 2026-11-22
token binding and attestation
This lesson builds a token server that checks each token at the origin for its lifetime, its single use, and its binding.
purpose
A passed task is worth only as much as the challenge token that it gives. If the origin does not check that token well, a solved task in one place opens the gate in a different place. You must know which server checks carry the security after the task ends.
objectives
- Describe the life of a token from its issue to its last use.
- Build a token server that verifies each token at the origin with a lifetime, a single-use check, and a binding.
- Explain why the single-use check must be consistent at the place of the verify step.
- Select the place where the gate accepts an attestation token in place of a task.
new terms
how it works
A challenge gives one product: a token. The task decides if the client gets a token. The server checks decide what the token is worth after that. I use five server checks, in this order:
| check | question | a fail means |
|---|---|---|
| Integrity | Did my server make this token? | The token is changed or made by a different party. |
| Origin verify | Does the origin check the token itself? | A form can accept a request with no valid token. |
| Lifetime | Is the token younger than its limit? | The token is too old. |
| Binding | Do the binding values agree with the values at the issue? | A different client presents the token. |
| Single use | Is this the first use of the token? | The token is used a second time. |
the issue step
The gate issues a token only after a pass. The token holds three values: a random token ID, the issue time, and a hash of the binding values.
A keyed hash of these three values makes the integrity check possible. For example, a token for the web session ws-0001 holds the hash of ws-0001, a network class, and a client class.
The key stays on the server. The client sees only the token, not the key.
the verify step at the origin
The origin verifies each token on its own server, before it accepts the form or the page request. A check in the browser does not count, because the client controls the browser.
The token lifetime is the first limit. A short lifetime gives a copied token little time, but a real user gets more tasks. A long lifetime saves tasks, but a copied token stays valid longer. The chart in the section "Data" shows the lifetimes that products document. More detail on this trade is in Challenge design: inputs, outputs, and the cost to a real user (not yet published).
the single-use check and the spent list
The single-use check accepts each token one time only. The server records each accepted token ID in a spent list. A second use of the same ID gets a refusal.
The spent list must be consistent at the place of the verify step. Some designs copy the list to many servers with a delay. Then a short window can exist in which two servers accept the same token.
For example, two requests with one token arrive at two servers in the same second, and both pass. Make the list consistent at the verify point, or write the window in the design as a known risk.
the binding check
A token that works from each client is easy to move. A session binding ties the token to the values of the client that got it. For example, a token from the web session ws-0001 on network class 1 fails when it arrives on network class 2.
Thus a token from a solver service with a different egress fails the binding check.
The binding does not stop a solve. It stops the move of a solved token to a different client.
The binding has a cost. A real user whose network changes during the lifetime also fails. Select the binding values by the value of the page.
fail open or fail closed
The verify step can fail for a reason that is not the client, for example a store of the spent list that does not answer. The design must say what the origin does then:
- Fail open: the origin accepts the request, and the gate loses its effect for that time.
- Fail closed: the origin refuses the request, and real users get an error.
Write the choice in the design for each route. Do not let a default decide it.
an attestation token in place of a task
Some clients can bring an attestation from their device, as a token.
In Privacy Pass, an attester checks the device.
An issuer then signs a token. A Private Access Token is such a token.
The gate can accept such a token in place of the visible task. The check of the device is then the work of the attester, not of the gate.
The origin does the redemption and learns that an attester vouched for the device. It does not learn which user holds the device. For example, a request with a valid token skips the task, and a request with no token gets the normal task.
An attestation token is a second way to pass. It is not a replacement for the server checks of the gate. The mechanism of the attestation is in Device and app attestation, and device-bound sessions (not yet published). A lab redeemer is in Integrate a Privacy Pass redeemer, and measure the token share (not yet published).
the two sides
| automation side | detection side |
|---|---|
| A token that the gate binds to the web session cannot move to a different client. A token from a solver with a different egress fails the binding check. A second use fails at the spent list. | Verify each token at the origin. Enforce the lifetime and the single-use check. Bind the token to the values of the web session. Accept an attestation token where the attester checks the device. |
design decisions
| option | gain | cost | when it is correct |
|---|---|---|---|
| A short token lifetime | A copied token has little time. | Real users get more tasks. | A page with a high value for each request, for example a login |
| A long token lifetime | Real users pay one time. | A copied token stays valid longer. | A page with a low value for each request |
| A spent list that is consistent at the verify point | No window for a second use | Each verify step waits for one store. | A token with a high value |
| A spent list with a copy delay | Fast verify steps on many servers | A short window for a second use | A low value, with the window written as a known risk |
| Bind to the web session and the network class | A moved token fails. | A user whose network changes gets a new task. | A token with a high value |
| Fail closed | No request passes without a check. | Real users get errors when the store does not answer. | A route where abuse costs more than an error |
| Accept an attestation token | Fewer tasks for clients with a device proof | The gate trusts the attester for the check of the device. | A route that keeps all other server checks |
diagram
the life of a challenge token at the origin
the gate accepts an attestation token in place of a task, and keeps its own server checks
The first diagram shows the life of one token. The second diagram shows the place of an attestation token.
code example
The example is a lab token server. It issues a token after a pass, and it verifies the token at the origin. The key lives only in the memory of the run, and the output prints no token and no key. Thus no real service accepts a token of this code.
The inputs are synthetic:
- Web session:
ws-0001, network class 1, client class 1. - Lifetime: 300 seconds.
- Time argument:
1000.
A token server. Issue a token and verify it at the origin. Enforce the lifetime and the single-use check, and compare a hash of the binding values.
// A lab token server: issue a token after a pass, and verify it at the origin.
// Synthetic web sessions only. No network. The key lives only in the memory of the run.
import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
type Attrs = { webSession: string; network: string; client: string };
const KEY = randomBytes(32);
const LIFETIME_S = 300; // a lab value for the token lifetime
const spent = new Set<string>(); // the spent list: token IDs that the origin accepted
const bindHash = (a: Attrs) =>
createHash("sha256").update(`${a.webSession}|${a.network}|${a.client}`).digest("base64url");
const mac = (body: string) => createHmac("sha256", KEY).update(body).digest();
// Issue: the gate calls this after a pass. The token holds an ID, the issue time, and the binding hash.
function issue(a: Attrs, now: number): string {
const body = `${randomBytes(12).toString("base64url")}.${now}.${bindHash(a)}`;
return `${body}.${mac(body).toString("base64url")}`;
}
// Verify at the origin: the integrity, the lifetime, the binding, and then the single-use check.
function verify(token: string, a: Attrs, now: number): string {
const parts = token.split(".");
if (parts.length !== 4) return "refuse: bad form";
const [id, issued, bound, tag] = parts;
const want = mac(`${id}.${issued}.${bound}`);
const got = Buffer.from(tag, "base64url");
if (got.length !== want.length || !timingSafeEqual(got, want)) return "refuse: integrity check failed";
const age = now - Number(issued);
if (age < 0 || age > LIFETIME_S) return `refuse: outside the lifetime (age ${age} s)`;
if (bound !== bindHash(a)) return "refuse: binding check failed";
if (spent.has(id)) return "refuse: token already spent";
spent.add(id);
return "accept";
}
const userA: Attrs = { webSession: "ws-0001", network: "net-class-1", client: "client-class-1" };
const otherNet: Attrs = { ...userA, network: "net-class-2" };
const t0 = Number(process.argv[2] ?? 1000);
const tok = issue(userA, t0);
console.log("1 first use, same web session: ", verify(tok, userA, t0 + 20));
console.log("2 second use: ", verify(tok, userA, t0 + 25));
const tok2 = issue(userA, t0);
console.log("3 other network: ", verify(tok2, otherNet, t0 + 20));
console.log("4 late use: ", verify(tok2, userA, t0 + 400));
const changed = tok2.replace(/\.(\d+)\./, (_m, s) => `.${Number(s) + 300}.`);
console.log("5 changed issue time: ", verify(changed, userA, t0 + 400));
console.log("spent list size:", spent.size);output
One result line for each of five synthetic presentations, and the size of the spent list.
1 first use, same web session: accept
2 second use: refuse: token already spent
3 other network: refuse: binding check failed
4 late use: refuse: outside the lifetime (age 400 s)
5 changed issue time: refuse: integrity check failed
spent list size: 1The output shows one accept and four refusals. The second use fails at the spent list. The token on a different network fails the binding check.
The late token fails the lifetime. A changed issue time fails the integrity check, because the keyed hash no longer agrees. The spent list holds one token ID: the one accepted token.
data
documented token lifetimes of nine products, on a log scale
status of this figure: copied from a public document
source: Public documentation of nine products; the link is one of nine pages (public source, https://developers.google.com/recaptcha/docs/verify, read 2026-11-12); date 2026-11-12; condition: Documentation read on 2026-11-12. Product 4 documents two lifetimes by challenge type. Product 7 documents a default and a maximum.
data table
| series | product | s |
|---|---|---|
| default or stated lifetime | product 1 | 120 |
| default or stated lifetime | product 2 | 120 |
| default or stated lifetime | product 3 (about) | 120 |
| default or stated lifetime | product 4, puzzle type | 180 |
| default or stated lifetime | product 4, image type | 900 |
| default or stated lifetime | product 5 | 300 |
| default or stated lifetime | product 6 | 300 |
| default or stated lifetime | product 7 | 300 |
| default or stated lifetime | product 8 | 1800 |
| default or stated lifetime | product 9 | 1800 |
| documented maximum | product 7 | 259200 |
The chart shows that the documented lifetimes go from minutes to days. Thus no single lifetime is a standard. Each gate must select its own value by the value of the page.
failure modes
| problem | cause | correction |
|---|---|---|
| A form accepts requests with no valid token. | The origin does not verify the token on its own server. | Verify each token at the origin before you accept the request. |
| A token works a second time. | The server has no single-use check. | Record each accepted token ID in the spent list, and refuse a second use. |
| Two servers accept the same token in one second. | The spent list is copied with a delay. | Make the list consistent at the verify point, or write the window as a known risk. |
| A solved token works from a different client. | The token has no binding to the web session. | Bind the token to the values of the web session at the issue. |
| Real users get many errors on one route. | The route fails closed when the store of the spent list does not answer. | Decide fail open or fail closed for each route, and write it in the design. |
| A client with an attestation token skips all checks. | The gate accepts the token and drops its own server checks. | Keep the lifetime, the binding, and the single-use check after the attestation token. |
check questions
Describe the life of a challenge token from its issue to its last use at the origin.
sample answer
The gate issues the token after a pass. The client presents it at the origin. The origin checks the integrity, the lifetime, the binding, and the single use. A token that passes each check goes into the spent list. A token that is too old expires, and a changed, moved, or second-use token gets a refusal.
A solved token arrives at the origin from a different network class, 20 seconds after its issue. The gate binds tokens to the web session and the network class. Which check refuses it?
- The integrity check
- The lifetime check
- The binding check
- The single-use check
answer
c. The binding check
The token is young and not changed, but its binding values do not agree with the values at the issue.
Where must the verify step of a challenge token occur?
- On the server of the origin, before it accepts the request
- In the browser, after the task ends
- In the browser, before the client sends the form
answer
a. On the server of the origin, before it accepts the request
The client controls the browser. Only a check on the server of the origin decides if the request has a valid token.
Explain why a spent list that many servers copy with a delay can let one token pass two times.
sample answer
Two requests with one token can arrive at two servers inside the copy delay. Neither server sees the token in its copy of the list, thus both accept it. A list that is consistent at the verify point closes this window, or the design writes the window as a known risk.
A gate accepts an attestation token in place of the visible task. Which part of the work does the gate give to the attester?
- The lifetime of the challenge token
- The single-use check at the origin
- The binding to the web session
- The check of the device
answer
d. The check of the device
The attester checks the device. The gate still issues its own challenge token, and the origin keeps the lifetime, the binding, and the single-use check.
exercise
exercise Do this task on paper, with the synthetic records below only. Do not send a request to a site.
The gate has these settings:
- Token lifetime: 300 seconds.
- Binding values: the web session and the network class.
- The spent list is consistent at the verify point.
Each record is one presentation of a token at the origin, in time order:
| record | token id | time since the issue | web session | network class | integrity |
|---|---|---|---|---|---|
| 1 | t-01 | 40 s | ws-0001 | 1 | valid |
| 2 | t-01 | 60 s | ws-0001 | 1 | valid |
| 3 | t-02 | 90 s | ws-0001 | 2 | valid |
| 4 | t-03 | 420 s | ws-0002 | 1 | valid |
| 5 | t-04 | 10 s | ws-0003 | 1 | not valid |
The token t-01 and the token t-02 were issued to ws-0001 on network class 1. The token t-03 was issued to ws-0002 on network class 1.
- For each record, write the first check that fails, in the order of the table of "How it works".
- For each record, write accept or refuse.
- Write the token IDs in the spent list after record 5.
sample answer
The answer uses the five synthetic records of the task.
Record 1 passes each check, thus the origin accepts it and t-01 goes into the spent list. Record 2 has the same token ID, thus it fails the single-use check. Record 3 arrives on network class 2, thus it fails the binding check. Record 4 is 420 seconds old, thus it fails the lifetime. Record 5 fails the integrity check first. After record 5, the spent list holds only t-01.
sources
- My model of the life of a challenge token, the five server checks, and a gate that accepts an attestation token, 2026-11 (not public).