Skip to content

Commit c344cc5

Browse files
docs(dde): reverse-proxy production posture — five rules, verified nginx snippet, backups, ops never-do list
New §6 subsection in the boundary document: all three guards key on the direct peer, so behind nginx/Caddy/Traefik the client-differentiated limits belong at the proxy (the app must not read forwarded headers — that is contract-tested), the app stays on the loopback bind, the allowlist pins the proxy's source address as containment for a misexposed port, the in-process limiter is resized as a backstop above the edge ceiling (never disabled), and body caps stay aligned. nginx directives verified against the official limit_req and core module docs. Backups: the endpoint is stateless — what must be preserved is the proxy config and the submitter's own fixtures; a restart resets rate budgets (bounded by the proxy backstop). The live API reference page's limits note now points at the posture. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 13b7b43 commit c344cc5

2 files changed

Lines changed: 89 additions & 2 deletions

File tree

‎docs/DDE-API-REFERENCE.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ <h2 data-i18n="h_sdk"></h2>
231231
pr_health_t:{en:"/health is always exempt",ar:"‏/health معفاة دائمًا"},
232232
pr_health_d:{en:"A flood can never consume liveness budget — otherwise the attack itself would hide the symptoms.",
233233
ar:"الفيضان لا يستطيع أبدًا حجز ميزانية الحيوية — وإلا صار الهجوم نفسه يخفي الأعراض."},
234-
limits_note:{en:"Limits are in-memory and per-process: horizontally scaled deployments should front the endpoint with their own limiter. The allowlist keys on the direct peer — put your proxy's address on the list, never trust forwarded headers.",
235-
ar:"الحدود في الذاكرة ولكل عملية: النشر الموسع أفقيًا يضع أمامه محدّده الخاص."},
234+
limits_note:{en:"Limits are in-memory and per-process: horizontally scaled deployments should front the endpoint with their own limiter. The allowlist keys on the direct peer — put your proxy's address on the list, never trust forwarded headers. Deploying behind nginx/Caddy/Traefik? Read the reverse-proxy production posture in the boundary document — five rules, a verified nginx snippet, backup guidance, and the ops never-do list.",
235+
ar:"الحدود في الذاكرة ولكل عملية: النشر الموسع أفقيًا يضع أمامه محدّده الخاص. القائمة المسموحة تعتمد العنوان المباشر — ضع عنوان الـproxy في القائمة، ولا توثق الترويسات المرسلة أبدًا. ستنشر خلف nginx/Caddy/Traefik؟ اقرأ وضعية الإنتاج خلف الوكيل العكسي في وثيقة الحد — خمس قواعد ومقتطف nginx موثق وإرشادات النسخ الاحتياطي وقائمة ممنوعات التشغيل."},
236236
h_sdk:{en:"In-process SDK — same contract, no wire",ar:"‏SDK داخل العملية — نفس العقد بلا شبكة"},
237237
sdk_intro:{en:"For platforms that prefer embedding: the same gate without the network hop.",
238238
ar:"للمنصات التي تفضل التضمين: نفس البوابة بلا قفزة الشبكة."},

‎docs/delivery-dispute-boundary.md‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,93 @@ refused (`422` — closure is established by `closedAtUtc`, never declared), and
252252
only a procedure-closed record releases funds. Evidence is admissible; conformity
253253
is decided by the parties, never by this endpoint.
254254
255+
### Running behind a reverse proxy — production posture
256+
257+
All three guards key on the **direct peer** — the socket address that connected
258+
to the Node process. Behind nginx/Caddy/Traefik/a cloud LB that peer is always
259+
the proxy, so the guards' meaning changes. The posture below keeps every
260+
fail-closed property intact; skip it and you get the two classic mistakes:
261+
one shared rate bucket for all your visitors (one heavy client locks everyone
262+
out), or an allowlist that either passes everything or nothing. The nginx
263+
directives shown are verified against the official `ngx_http_limit_req_module`
264+
and core-module documentation (zone/burst/nodelay syntax, `client_max_body_size`
265+
default of 1m); adapt names to your proxy if it is not nginx.
266+
267+
**The five rules:**
268+
269+
1. **Client-differentiated limits live at the proxy, not the app.** The app
270+
cannot do them honestly — it must not read `X-Forwarded-For` (contract-tested:
271+
forged headers cannot mint identity, for the limiter and the allowlist
272+
alike). The proxy applies its own per-client rate limiting keyed on what
273+
*it* believes the client is:
274+
275+
```nginx
276+
# rate-limit real clients at the edge (the app cannot — it keys on the
277+
# socket peer, which is this proxy)
278+
limit_req_zone $binary_remote_addr zone=dde:10m rate=10r/s;
279+
server {
280+
listen 443 ssl;
281+
location / {
282+
limit_req zone=dde burst=20 nodelay;
283+
client_max_body_size 1m; # keep the edge cap ≤ the app's 1 MiB
284+
proxy_pass http://127.0.0.1:8787;
285+
proxy_set_header Host $host;
286+
# X-Forwarded-For may be set for downstream LOGGING — the app ignores it
287+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
288+
}
289+
}
290+
```
291+
292+
2. **Bind the app to loopback only.** The default `host: "127.0.0.1"` stays —
293+
never `0.0.0.0` "behind a proxy": that recreates a public bind whose guards
294+
key on the wrong peer. The app is reachable only through the proxy.
295+
296+
3. **Allowlist = pin the proxy's source address(es).** With the proxy on the
297+
same host, `allowAddresses: ["127.0.0.1"]` means the app accepts traffic
298+
from the proxy alone — a briefly misexposed port is still gated. On a
299+
private network, list the proxy hosts' addresses. (They all share one
300+
verdict: the proxy is the front door by design.)
301+
302+
4. **The in-process rate limiter becomes a backstop, not the primary limiter.**
303+
Size it above the proxy's per-client ceiling (e.g. `rateLimit: {
304+
windowMs: 60_000, max: 600 }` for a 10 r/s edge limit) so it only fires on
305+
aggregate floods or a misconfigured proxy. Do **not** disable it
306+
(`rateLimit: false`) unless something in front always limits — the
307+
in-process budget is the last line of defense.
308+
309+
5. **Keep the body caps aligned.** `client_max_body_size` (or your proxy's
310+
equivalent) ≤ the app's 1 MiB cap, so oversized bodies die at the edge and
311+
the app's two-layer gate remains the truth for anything that slips through.
312+
313+
**Production settings at a glance:**
314+
315+
| Setting | Direct bind (default) | Behind a reverse proxy |
316+
|---|---|---|
317+
| `host` | `127.0.0.1` | `127.0.0.1` (proxy on same host) or a private interface — never `0.0.0.0` |
318+
| `rateLimit` | `120/min` per real client | backstop per proxy, sized **above** the proxy's per-client ceiling (e.g. 600/min); primary limiting at the edge |
319+
| `allowAddresses` | omit — the loopback bind *is* the guard | pin the proxy's source address(es) — containment for a misexposed port |
320+
| body cap | 1 MiB (two layers) | 1 MiB, with the edge cap ≤ 1 MiB so oversize dies at the proxy |
321+
| TLS | out of scope (loopback) | terminated at the proxy; the app speaks plain HTTP over loopback/private net |
322+
323+
**Backups and recovery.** The endpoint is stateless by design: no database, no
324+
persisted fixtures, rate-limit state is per-process memory. There is nothing
325+
to back up at the app layer. Back up instead: (1) the **reverse-proxy config**
326+
— it carries the real client-identity and edge-limit policy, which is the part
327+
that cannot be reconstructed from this repo; (2) any fixtures *you* submitted
328+
are yours — the endpoint keeps nothing. A process restart resets rate budgets
329+
(fail-safe: it briefly trusts more); behind the recommended proxy backstop
330+
that window is bounded and invisible. Proxy upstream health checks should
331+
target `/health` — it is exempt from the rate limiter and returns the boundary
332+
banner; remember the exemption is per-endpoint: `/health` free does not mean
333+
`/verify` free.
334+
335+
**Never do (ops edition):** bind `0.0.0.0` and rely on the app guards as if
336+
the peer were the client · make the app read forwarded headers to "fix"
337+
per-client limiting (the contract forbids it — the fix is at the proxy) ·
338+
publish the app's port alongside the proxy's · point untrusted third parties
339+
at the app behind the proxy: the proxy **is** the front door, and every app
340+
side guard assumes the door is the proxy.
341+
255342
## 7. What this design deliberately does not do
256343
257344
- It does not judge who is right. Both positions survive verbatim.

0 commit comments

Comments
 (0)