Skip to main content
← CONCEPTS / SECURITY
An end-to-end domain learning journey

Decentralized Capability Tokens: Macaroons,
Biscuit & Offline Attenuation.

Forwarding static JWTs across multi-hop services creates confused-deputy risks, while online IdP token exchange adds latency and a central SPOF.
Start the journey5 sections· Last modified Nov 25, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When multi-hop services or AI agents must narrow a user's permissions without calling the Identity Provider on every hop, use offline-attenuated capability tokens (Biscuit or Macaroons) so callers can append restrictions cryptographically without being able to strip them.

TL;DR30-second simplified summary
▾

When Service A calls Service B and passes along the user's bearer JWT, Service B inherits the exact same broad permissions as Service A—even if Service B only needed read-only access to one folder for 30 seconds. Narrowing a traditional JWT requires an online round-trip to the Identity Provider (token exchange), adding latency and turning the IdP into a runtime single point of failure.

Decentralized capability tokens—Macaroons (symmetric HMAC chaining) and Biscuit (asymmetric Ed25519 + Datalog policies)—solve this with offline attenuation. Any holder of a token can append a new restriction (caveat, such as op=read or exp < now + 60s) without contacting the issuer. Because each caveat is cryptographically chained into the signature, stripping a caveat invalidates the token, while appending a caveat strictly narrows what the token can do.

The key architectural choice is symmetric vs. asymmetric verification: Macaroons verify fast with HMAC-SHA256 but require sharing a secret with the verifier, whereas Biscuit uses Ed25519 public-key verification so any microservice can verify attenuated tokens locally.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Bearer Tokens & JWTs
A signed token grants anyone holding it the permissions encoded inside until it expires.
HMAC vs. Asymmetric Signatures (Ed25519)
HMAC uses one shared secret for both signing and verifying; Ed25519 signs with a private key and verifies with a public key.
Full walkthrough · 5 stages
01
P · PROBLEM & BROKEN TRACEfoundation

Why Forwarding Static Bearer JWTs Creates Confused Deputies.

Why this matters: Show how forwarding an un-narrowed JWT across microservices or AI agents leaks broad authority and why online IdP token exchange bottlenecks.

Suppose Alice logs in and gets a bearer JWT with scope: bucket:prod:rw valid for 1 hour. She asks Service A to generate a PDF report; Service A forwards her JWT to Service B (an untrusted PDF renderer), which only needs to read /reports/alice.csv.

Because a JWT's RSA/EdDSA signature covers a fixed payload signed by the Identity Provider (IdP), Service A cannot edit the JWT to say read-only or prefix=/reports. If Service B is compromised—or tricked via SSRF—it holds Alice's full bucket:prod:rw key.

The naive fix is OAuth2 On-Behalf-Of Token Exchange: Service A calls the IdP before calling Service B to mint a narrower JWT. At 50,000 internal RPCs/sec across 5 hops, that adds 5 synchronous IdP round-trips per request and turns the IdP into a global SPOF.

CONFUSED DEPUTY TRACE

Static JWT Forwarding vs. Offline Token Attenuation

Service AService B(Renderer)Storage API1. Forwards full JWT (prod:rw)2. Compromised B deletes/prod/users!3. Biscuit + Caveat(read,/reports, 60s)4. Storage blocks /prod/userslocally

Offline attenuation restricts downstream services to least privilege without contacting the Identity Provider.

02
R · REPRESENTATION & INTUITIONfoundation

HMAC Chaining (Macaroons) vs. Ed25519 + Datalog (Biscuit).

Why this matters: Compare how Macaroons and Biscuit bind caveats cryptographically so anyone can add restrictions offline but nobody can remove them.

Macaroons chain HMAC-SHA256 tags: the issuer computes t0=HMAC(Kroot,id)t_0 = \text{HMAC}(K_{\text{root}}, \text{id}). To add caveat c1c_1, Service A computes t1=HMAC(t0,c1)t_1 = \text{HMAC}(t_0, c_1) and ships (id, [c1], t1)—discarding t0t_0. Because SHA-256 is one-way, Service B cannot invert t1t_1 back to t0t_0 to drop c1c_1, yet the storage verifier (which knows KrootK_{\text{root}}) can recompute the chain.

Biscuit solves Macaroons' shared-secret limitation using asymmetric Ed25519 block chaining plus a tiny embedded Datalog logic engine. The issuer signs Block 0 with its private root key; anyone can append Block 1 (carrying check if operation == "read") signed with an ephemeral keypair baked into the chain. Downstream services verify the entire chain using only the issuer's public key.

CRYPTOGRAPHIC CHAIN

How Biscuit Blocks Chain Ed25519 Signatures & Datalog Caveats

Each appended block narrows authority cryptographically; removing any block breaks the signature chain.

ChoiceWhat it buysWhat it costs
Static JWT (OAuth2)Stateless public-key verify; universal library support.Cannot attenuate offline; broad scope leaks across multi-hop calls.
Macaroons (HMAC Chain)Ultra-fast symmetric HMAC (~1 us); tiny wire size; offline attenuation.Verifier must share symmetric root secret with issuer (harder across org boundaries).
Biscuit (Ed25519 + Datalog)Asymmetric public-key verify + expressive Datalog policies + offline attenuation.Larger token (~300–800B) and Ed25519 verify cost (~50–100 us per block).
03
I · INVARIANT & IMPLEMENTATIONintermediate

Enforcing Monotonic Attenuation & Fail-Closed Caveat Verification.

Why this matters: Implement a deterministic caveat-chain verifier that rejects stripped caveats, expired tokens, and unmet Datalog predicates.

The core security invariant is monotonic attenuation: a derived token's allowed action set must always be a subset of its parent's.

import hashlib, hmac

class MacaroonVerifier:
    def __init__(self, root_key: bytes) -> None:
        if len(root_key) < 32:
            raise ValueError('Root key must be >= 32 bytes')
        self.root_key = root_key

    def attenuate(self, tag: bytes, caveat: str) -> bytes:
        if not caveat or '=' not in caveat:
            raise ValueError('Caveat must be non-empty key=val')
        return hmac.new(tag, caveat.encode(), hashlib.sha256).digest()

    def verify(self, token_id: str, caveats: list[str], presented_tag: bytes, ctx: dict) -> bool:
        tag = hmac.new(self.root_key, token_id.encode(), hashlib.sha256).digest()
        for cav in caveats:
            tag = hmac.new(tag, cav.encode(), hashlib.sha256).digest()
        if not hmac.compare_digest(tag, presented_tag):
            return False  # Tampered or stripped caveat
        return all(self._check_caveat(c, ctx) for c in caveats)

    def _check_caveat(self, cav: str, ctx: dict) -> bool:
        k, v = cav.split('=', 1)
        if k == 'op':
            return ctx.get('op') == v
        if k == 'exp':
            return int(ctx.get('now', 1 << 62)) <= int(v)
        return False  # Fail closed on unknown caveat
VERIFICATION INVARIANT

Cryptographic Chain Check Followed by Fail-Closed Caveat Evaluation

tag mismatchsig validall caveats trueRecompute ChainHMAC / Ed25519Reject 401Tampered / StrippedEvaluate CaveatsAll Must PassAllow Scoped OpLeast Privilege

Constant-time signature verification plus fail-closed caveat evaluation prevents privilege escalation.

04
M · MECHANICS AT SCALEintermediate

Ed25519 Verification Cost, Revocation IDs & Simulation.

Why this matters: Quantify verification CPU cost at 50K RPS and handle emergency revocation without turning every request into a DB lookup.

Verification cost scales linearly with the number of appended blocks. At ~50–100 us per Ed25519 verification on modern x86_64 cores, a 3-block Biscuit token takes ~200 us (~5,000 verifications/sec per CPU core), whereas Macaroon HMAC-SHA256 takes ~2 us.

Because capability tokens are verified offline, revoking a compromised root token before expiry requires a lightweight revocation ID per block (revocation_id = hash(block_sig)). Edge gateways hold a small Redis/in-memory revocation set (only active revoked IDs until their exp passes) rather than storing every issued token.

Interactive Visual Simulation

Offline Attenuation & Tamper Detection Flow

issuer

Auth Issuer

Root Ed25519 Key

1. Root Biscuit (r/w)
svca

Service A

Appends op=read

2. Append Block 1 (read)
attk

Compromised Hop

Tries Strip Caveat

3. Present Modified Token
stor

Storage Verifier

Public-Key Verify

scope

prod:rw

blocks

1

idp_calls

1

Mint Root CapabilityHealthy
Issuer mints root Biscuit for Alice; no further IdP calls will be needed.
05
E · EDGE CASES, EXCLUSIONS & GLOSSARYadvanced

When NOT to Use Capability Tokens, Assumptions & Glossary.

Why this matters: Identify workloads where OAuth2 JWTs remain simpler, document revocation assumptions, and define core terms.

When NOT to Use Macaroons or Biscuit

  • Single-hop browser-to-API apps: If tokens never cross untrusted downstream services or AI agents, a short-lived standard JWT is simpler and universally supported by third-party SaaS gateways.
  • Strict instant global kill-switch: Offline verification means a pushed revocation list has propagation lag (e.g., 1–5s); ultra-sensitive bank wires should pair tokens with an online session check.

Assumptions & Limitations

  • Clock Sync: Time-based caveats (exp < now + 60s) assume bounded NTP clock skew across services.
  • Datalog Guardrails: Biscuit evaluators bound Datalog execution steps/facts (max_facts, max_iterations) to prevent adversarial tokens from triggering CPU DoS.

Concise Glossary

  • Offline Attenuation: Narrowing a token's permissions locally by appending cryptographic restrictions without contacting the issuer.
  • Caveat: A predicate/restriction attached to a token (e.g., read-only, path prefix, expiry) that must hold at verification time.
  • Confused Deputy: A privileged service tricked into misusing its broad authority on behalf of a less-trusted caller.
  • Macaroon: Capability token using chained symmetric HMAC-SHA256 signatures.
  • Biscuit: Capability token using asymmetric Ed25519 signature chains and a bounded Datalog policy engine.
Decision Exercise · Make the Call

An autonomous AI agent needs to delegate a 30-second read-only task on /reports/q4.csv to a third-party sandboxed tool worker without calling the central IdP. Which token design fits best?

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 4
Score: 0/4

Why can't Service A simply edit a standard JWT's `scope` claim from `rw` to `read` before forwarding it to Service B?

Recommended Learning Flow