ProxyAuth / Security

The token isn't just encrypted — the binary is part of the secret

ProxyAuthSecurity / CryptographyUpdated on 2026-09-18

Most reverse proxies that issue their own session tokens do one of two things: sign with a shared secret and stop there, or lean on a database every instance can query. ProxyAuth does neither. Part of what makes a token valid is baked into the binary at compile time — and that one design choice explains most of how multi-node deployments work.

One vault, built once

Everything cryptographic about a token — key derivation, sealing, the signature, the optional obfuscation pass — lives in the zerocrypt library. ProxyAuth’s job is to map its configuration and build constants onto one process-wide vault at startup.

That vault is immutable afterwards and Send + Sync. Every worker thread, and every num_instances server in the process, shares the same instance with no lock on the request path.

Two secrets, not one

InputContributesSource
secretthe operator secretconfig.json
build_hk (32 bytes)the build’s real entropy, drawn from the OS CSPRNG by build.rscompile time
build_time, build_rand, build_epochdate, field orderingbinding — any difference yields a different keycompile time

build_hk is validated before it is adopted, so an instance always runs with a build secret at full length. The other constants are not there for entropy; they bind the key to one specific build.

All of it is folded into a single 32-byte key through BuildKey::derive, under the domain string proxyauth.token.v1. Two consequences:

  • Domain separation. Another caller feeding identical material into the same library under a different domain gets an unrelated key.
  • No rearrangement collisions. The parts are length-prefixed inside the derivation, so no reshuffling of their bytes can produce the same input as a different set of values.

The binding is applied once, in key derivation, rather than recomputed on every signature. Verifying a token therefore costs only the cryptography, while the token stays tied to the build that issued it.

What that means for a second instance

Compile the same source twice, give both binaries the same secret, and a token issued by one is rejected by the other. Their build constants differ, so their keys differ.

That is not a bug to work around; it is a property to use. Two ways to make instances agree:

  1. Ship the same artifact everywhere, with the same secret.
  2. proxyauth sync export / proxyauth sync — carry one build’s constants to other instances, deliberately, over an encrypted keystore. An import carrying a build secret shorter than 32 bytes is refused, so an instance never downgrades its key derivation.

The sync groups post shows how to turn this into segmentation: instances trust each other only where you carried the constants.

The threat this addresses is concrete. A shared secret alone protects against someone who does not have it. It does nothing against a different binary — a modified build, a fork with a weakened check — handed the same secret. Tying the key to the build means secret leaking from config.json is not, on its own, enough to mint tokens a fleet of other builds will accept.

fast: the obfuscation pass

{ "fast": false }
  • false (default) — an extra obfuscation pass runs on top, keyed by BUILD_SEED2. That seed must fall in 10..=99; a binary built with anything else refuses to start and names the value. The cost is a higher work factor per verification.
  • true — the pass is skipped, and the hot proxy path trades some request-time flexibility for raw throughput.

The value is read once at startup, never per request.

The verification cache

The vault keeps up to 50 000 successfully verified tokens. The bound is deliberate: the cache key is a live token, and an unbounded map keyed by attacker-supplied strings is a memory-exhaustion primitive. At roughly 300 bytes per entry, that is a few megabytes. A deployment with more live sessions than that sees a lower hit rate, not unbounded growth.

There is one cache per process. num_instances does not start processes, so the figure is a whole-host bound, not a per-instance one.

What the cache does not cover

This is the operationally important part. The cache stores only successful verifications and re-checks the token’s own expiry on every hit. It knows nothing about the rest, and the rest is re-checked after every vault call, cached or not:

StepCached?
decrypt, verify signature, check the token’s own expiryyes
resolve the user by index encoded in the tokenno — every request
check expiry against the current token_expiry_secondsno — every request
check the token ID against the revocation setno — every request

So revoking a token, editing a user, or lowering token_expiry_seconds takes effect on the next request, not when a cache entry ages out.

Why users are resolved by index

A token carries the index of its user, not the username. When a database-backed user’s row disappears, its slot is poisoned rather than removed. Removing it would shift the index of every entry after it — and those indexes are already embedded in issued tokens, which would then point at the wrong people. A token pointing at a poisoned index is rejected outright.

Operational checklist

  • Generate secret — 64 random characters or more — never type it.
  • Keep config.json owner-only; it holds secret and token_admin.
  • For several nodes: same artifact everywhere, or sync on purpose.
  • Configure redis if a revocation must reach other nodes; without it, revocation is local.
  • Leave fast: false unless measurements say the pass matters.

Two secrets — one you configure, one the compiler drew for you — folded into one key under one domain, verified through a bounded cache that never gets to decide on revocation, users or expiry policy. Keeping every instance on the same build is not a footnote; it is the boundary.