Anti-Replay Protection (plugin_anti_replay)
This page explains ProxyAuth's request-signing anti-replay plugin — how a client proves a specific request really came from it, at the exact moment it claims, and can't be replayed later. It's a separate mechanism from session cookies/CSRF (see CSRF Protection): where CSRF protects a browser session against a third-party site forging a request, anti-replay protects any client — browser extension, script, service — by requiring every request to be individually signed with a per-account secret.
Anti-replay protection only applies when plugin_anti_replay is true in config.json and the matched route has need_anti_replay: true (the default) in routes.yml. If either is off, none of this runs.
Enabling it
{
"plugin_anti_replay": true,
"anti_replay_window_secs": 60
}
| Key | Type | Default | Description |
|---|---|---|---|
plugin_anti_replay |
boolean | false |
Enables signature verification on proxied requests. Off by default — fully opt-in, existing deployments are unaffected until this and at least one account with a signing secret exist. |
anti_replay_window_secs |
integer (seconds) | 60 |
How far a request's X-Timestamp may drift from the server's clock, in either direction, before being rejected. Also doubles as the nonce-replay window — see Nonce store & replay window below. |
Per-route, in routes.yml:
routes:
- prefix: /api
target: http://backend:3000
need_anti_replay: true
| Key | Type | Default | Description |
|---|---|---|---|
need_anti_replay |
boolean | true |
Per-route override, mirroring need_csrf's shape. Only has any effect when the server-wide plugin_anti_replay is also true. Set to false on routes that shouldn't require a signature (e.g. a health check, or a route with no signing clients). |
How signing works
A signing client attaches four headers to each request:
X-User: <ProxyAuth username>
X-Timestamp: <Unix time, milliseconds>
X-Nonce: <random bytes, base64, unique per request>
X-Signature: <HMAC-SHA256, base64>
The signature covers a canonical string built from the request itself:
METHOD|scheme|host|port|path|query|timestamp|nonce|username|bodyHash
method— uppercase HTTP method (GET,POST, …).scheme/host/port— as seen by the client, from the request's own URL/Hostheader, not the backend it's proxied to.path— request path, no query string.query— the query string including its leading?, or an empty string if there is none.timestamp/nonce— the same values sent asX-Timestamp/X-Nonce.username— the same value sent asX-User.bodyHash— base64 SHA-256 of the raw request body, or an empty string for a bodyless request.
All fields are joined with | and HMAC-SHA256'd with the account's signing secret. ProxyAuth reconstructs this exact string server-side from the incoming request and verifies the signature against the secret it has on file for that X-User.
Where the secret comes from
Unlike a manually-provisioned API key, there's nothing to register by hand. The signing secret lives directly on the account:
- Every
Userhas ananti_replay_secretfield — always ciphertext at rest (encrypted with a key derived fromconfig.secret), whether the account is defined inconfig.jsonor in a database-backeduserstable. - The first time an account is seen with
plugin_anti_replay: trueand no secret on file yet — at config load (file-based accounts), on the next database refresh cycle, or immediately viaproxyauth db-add-user(database-backed accounts) — a secret is generated automatically. - It's emailed once to the account's on-file address, using the
{{ secret_anti_replay }}placeholder in/etc/proxyauth/mail/templates/anti_replay_secret.txt(created automatically with a sensible default on first use, same convention asreset_password.txt— see config.json Reference § SMTP). - The plaintext secret is never stored anywhere past that email — if it's lost, clear
anti_replay_secretfor that account (config.json, orUPDATE users SET anti_replay_secret = NULL WHERE username = ...) so a new one is generated and mailed on the next load/refresh. - An account with no email on file gets a secret generated but not delivered — a warning is logged, and the secret has to be communicated out of band or the account given an email so it can be re-sent.
Because the secret is generated and mailed automatically, plugin_anti_replay needs smtp configured to be practically usable — see config.json Reference § SMTP.
Verification: what has to be true
For every request on a route with anti-replay enabled, ProxyAuth checks, in order:
- Headers present and well-formed —
X-User,X-Timestamp,X-Nonce,X-Signatureall present, non-empty, andX-Signaturevalid base64. - Known signing account —
X-Usermatches an account with a currently-decryptableanti_replay_secreton file. - Timestamp within window —
X-Timestampis withinanti_replay_window_secsof the server's own clock, in either direction. - Signature matches — the canonical string is rebuilt from the actual request (method, URL, body) and compared, constant-time, against a fresh HMAC-SHA256 computed with the account's secret.
- Not already used — see Nonce store & replay window below.
Any failure returns 401 Unauthorized with a small JSON body identifying the reason:
| Reason | Meaning |
|---|---|
missing_or_malformed_signature_headers |
One of the four headers is missing, empty, or not valid base64. |
unknown_signing_client |
X-User doesn't match any account with a usable signing secret. |
timestamp_out_of_window |
X-Timestamp is too far from the server's clock — check both clocks are in sync. |
invalid_signature |
The HMAC doesn't match — wrong secret, or the request (method/URL/body) was modified after signing. |
replayed_request |
This exact (username, nonce) pair was already consumed. |
Nonce store & replay window
A valid signature alone isn't enough — a captured signed request could otherwise be sent again as-is. Every (username, nonce) pair is recorded the first time it's successfully verified:
- Tracked in memory (a
DashMap) and mirrored to a dedicated local LMDB store, so a restart doesn't reset the replay window to empty. - A nonce only needs to be remembered for as long as its timestamp could still pass the window check anyway — entries are purged automatically on an interval tied to
anti_replay_window_secs. - Replaying a request with the same nonce and timestamp fails with
replayed_request, even though the signature itself is still technically valid.
Like the CSRF nonce store, this is per-process and not synchronized across instances. In a multi-instance deployment without shared state, a captured request could in principle be replayed once against a different instance within the tolerance window — bounded by
anti_replay_window_secs, same as the window itself. Sticky sessions at the load balancer avoid this; a shared nonce store across instances isn't currently implemented (unlike token revocation — see Token Revocation & Multi-Instance Sync).
Signing from a browser: the ProxyAuth extension
The reference implementation is the ProxyAuth browser extension (Firefox and Chrome), which signs outgoing requests to configured domains transparently:
- The user configures, per domain: their ProxyAuth username, the domain/path to sign, and the secret received by email.
- Signing happens automatically for matching HTTPS requests — nothing to do per-request.
- The HMAC secret is encrypted at rest locally (AES-GCM, a device-local key generated once — no master password to manage) and never leaves the extension's background context.
Firefox (Manifest V2) intercepts at the network level (webRequest.onBeforeSendHeaders) and can sign any request type. Chrome (Manifest V3) — which removed synchronous network interception for consumer extensions — instead patches fetch()/XMLHttpRequest in the page's own context, relaying signing requests through an isolated bridge to a service worker that alone holds the secret. Practical consequence: on Chrome, only fetch()/XMLHttpRequest calls are signed, and cross-origin requests may trigger a CORS preflight that wasn't there before — make sure Access-Control-Allow-Headers includes X-User, X-Timestamp, X-Nonce, X-Signature on signed routes if your frontend and API are on different origins.
Summary
| Property | Value |
|---|---|
| Headers | X-User, X-Timestamp, X-Nonce, X-Signature |
| Signature algorithm | HMAC-SHA256, keyed by the account's anti_replay_secret |
| Comparison | Constant-time |
| Secret storage | Per-account (User.anti_replay_secret), ciphertext at rest, config.json/LMDB cache/database all supported |
| Secret provisioning | Automatic on account creation/first sight, emailed once via {{ secret_anti_replay }} |
| Replay window | anti_replay_window_secs (default 60s), enforced via timestamp check + nonce store |
| Nonce store persistence | In-memory + local LMDB; not synced across instances |
| Per-route opt-out | need_anti_replay: false in routes.yml |
| Default state | Off (plugin_anti_replay: false) |
See also
- config.json Reference —
plugin_anti_replay,anti_replay_window_secs. - routes.yml Reference — per-route
need_anti_replayoverride. - Database-Backed Users — the
anti_replay_secretcolumn on theuserstable. - CSRF Protection — the companion mechanism for cookie-based sessions.
- Security Model: Why
secretAlone Isn't Enough — the broader threat-model context this fits into.
📖 Wiki Home · 💻 Source Code · 🐛 Report an Issue · 📜 License
Found an error or something outdated on this page? Open an issue or submit a PR against the wiki repository.