# Sequencer

The Sequencer estimates how unpredictable the tokens an application
issues are: session identifiers, CSRF tokens, password reset codes. Open
it from the Proxy tools.

## Collecting tokens

- **From history**: choose what to read (a **cookie** the responses set,
  a response **header**, or a **body pattern** whose first group is the
  token, read from the decoded body) and which flows to read it from, as
  a history search (`/login source:browser`, empty for all), at most
  20,000 flows, newest first. Requests that issue a fresh token are the
  ones to collect: log in many times, or call the endpoint that hands out
  the token, then analyse.
- **Pasted**: one token per line.

Only statistics come back. The tokens never leave the backend, so an
agent can analyse session cookies without reading them; reading history
still needs `http_evidence.read`.

## Reading the report

| Part | Says |
|---|---|
| Verdict | **Not enough tokens** under 100; **Weak** when tokens repeat, a bit test fails or fewer than 64 bits vary; **Strong** from 112 bits with no finding; **Reasonable** in between |
| Effective bits | Per character position, the Shannon entropy of what was seen there, capped by what the sample can show (log2 of the number of tokens) and by the characters seen; summed over positions |
| Sample could show | The most the sample could measure; when effective bits reach it, collect more tokens |
| Duplicates | A sound generator practically never repeats in a sample this size |
| Bits by position | One bar per position: constant prefixes, counters and timestamps show as low bars |
| FIPS 140-2 | Monobit, poker, runs and long run on the first 20,000 bits the characters encode, when all tokens have one length and the alphabet size is a power of two (hex, base32, base64); otherwise the report says why they did not run |

## What it cannot show

Statistics can show that tokens are weak; they can never prove that they
are unpredictable. A counter or a timestamp passed through a hash looks
random to every test here. Positions are analysed independently, so
correlations between positions or between consecutive tokens are not
detected, and a small sample understates strong tokens. Treat a strong
result as "no weakness found", not as proof.

## REST and MCP

`POST /api/v1/vaults/{vault_id}/sequencer/analyze` with either
`{"samples": [...]}` or `{"source": {"kind": "cookie" | "header" |
"body", "name", "pattern", "search", "limit"}}`. The MCP tool
`sequencer_analyze` takes the same choices.
