Skip to content

auth: the peer rate limit keys on REMOTE_ADDR, so the edge turns 20 requests per 10 minutes into a site-wide login lockout #3502

Done

Description

@Birfy

What is wrong

The authentication rate limiter keys its per-client bucket on REMOTE_ADDR, and nothing in the documented deployment makes REMOTE_ADDR per-client.

  • flybot_workspace/app.py:211-234 builds three buckets per auth request: peer:<REMOTE_ADDR> (default 20), name:<username> (default 10) and global (default 100), over a 600 s window (app.py:60-63).

  • app.py:212 reads env.get('REMOTE_ADDR') and nothing else. The application never reads X-Forwarded-For; grep -rn "X-Forwarded-For" flybot_workspace/*.py matches only dsbot_gateway.py, inside the rendered /social/ block.

  • server.py:71-72 comments that the server "binds to loopback only" and passes 127.0.0.1 to make_server. The documented front door is the rendered edge nginx (docs/ARCHITECTURE.md:25-26): python -m flybot_workspace.dsbot_gateway render --platform 127.0.0.1:8080 ..., whose location / (rendered from dsbot_gateway.py:766-771) does

    location / {
      proxy_pass http://127.0.0.1:8080;
      proxy_set_header Host $host;
      proxy_set_header X-OT-Gateway-Key "";
    }
    

    with no proxy_set_header X-Forwarded-For (only the /social/ block sets it, dsbot_gateway.py:791).

So behind the documented edge every browser reaches the platform from the edge's address: the peer bucket is one bucket for the whole instance, and its 20-per-600 s budget is shared by every registration, login and OIDC start.

Why it matters

auth_peer_limit is 20 and auth_window is 600 s, so the entire instance gets 20 authentication attempts per 10 minutes, independent of how many clients or users there are. Twenty requests from one anonymous client exhaust it, and then everybody is refused with 429 rate_limited and Retry-After: 600 — including users whose password is correct, and including registration. The name (10) and global (100) buckets never bind first, so they cannot absorb this.

There is also no operator knob: the limits are dataclass fields (app.py:60-63), server.py:34-47 exposes no flag for them, and nothing reads them from the environment.

Reproduction

Exact commit: c7c27e22c5a7da21fc2016136597673b42facfc3 (main at the time of writing).

python3 -m flybot_workspace.server --data-dir /tmp/d --origin http://127.0.0.1:8080 \
    --port 8080 --insecure-local --open-registration

Then 22 POST /v1/auth/register requests, each carrying a different X-Forwarded-For (so any per-client honouring of the header would put them in different buckets), all with Origin: http://127.0.0.1:8080 and the body {"username": "repro_user_<n>", "password": "Zx9-passphrase-42"}:

 1  X-Forwarded-For: 198.51.100.1   -> 201  ok
 ...
20  X-Forwarded-For: 198.51.100.20  -> 201  ok
21  X-Forwarded-For: 198.51.100.21  -> 429 Retry-After: 600 {"error":{"code":"rate_limited","message":"Authentication request limit reached; try later"}}
22  X-Forwarded-For: 198.51.100.22  -> 429 Retry-After: 600 {"error":{"code":"rate_limited","message":"Authentication request limit reached; try later"}}

An account created in the first 20 is then refused too:

POST /v1/auth/login {"username": "repro_user_1", "password": "Zx9-phrase-…"}  -> 429 Retry-After: 600

Expected vs actual

Expected: the peer bucket distinguishes clients, so one client's 20 attempts do not become every client's limit; and an operator who puts the documented edge in front can still tell an operator-set limit from a runaway client.

Actual: one bucket shared by every client, 20 auth operations per 10 minutes instance-wide, and a 20-request unauthenticated lockout of login and registration with Retry-After: 600.

Scope of this report

  • Measured against the app directly on loopback; this report does not run a real nginx. The deployment claim rests on the renderer in this repository (render --platform 127.0.0.1:8080) plus app.py:212; if an operator terminates in front of a non-loopback platform address, the bucket is that proxy's address instead of loopback, which is the same collapse.
  • Not claiming the limits themselves are wrong, or that X-Forwarded-For should be trusted blindly. docs/REGISTRATION.md states that forwarded headers are not accepted as identity; a rate-limit key is not identity, and the sibling service already models the operator-set allowlist this needs (services/bot-social/src/trust-proxy.ts, Refs deploy: the isolated Bot Social overlay's TRUST_PROXY default makes the service refuse to start #3498).
  • Only the auth routes are affected: rate_limit is called from POST /v1/auth/register, POST /v1/auth/login and POST /v1/auth/oidc/start. Existing sessions keep working.

Possible slice

One decision and one change: either the peer bucket is keyed on a forwarded client address when the direct peer is inside an operator-configured trusted-proxy list, or the three limits become operator-configurable (CLI or a private config file) with the deployment docs stating what the edge does to REMOTE_ADDR. Either way the regression test is the same: two clients simulated with one loopback peer must get separate peer buckets once the proxy is trusted, and must not be able to spend one another's budget.

Related: #3498 (the isolated Bot Social overlay's TRUST_PROXY handling).

Activity

  1. added
    agent-ready
    on Dec 3, 2026
  2. Birfy commented on Dec 3, 2026

    @Birfy
    CollaboratorAuthor

    Claiming this under the usual rule: branch dev/3502-auth-peer-limit-behind-edge from current main. Opening this issue was the only write action so far: it was created from the reporter's verbatim draft (5,188 B, sha256 9f89cb3e8a13b44743396382a5c6c05e5f19a4adc40ddbf6f9a36abe87667557), checked against the 39 open issues for a duplicate on auth rate limiting (none; #3498 is the Bot Social overlay's TRUST_PROXY, #3500 is a manifest key).

    Note on the last line: it reads Related: #3498, which is a plain reference, not a closing keyword, so nothing gets closed by it.

    Not scheduled yet: the two options in the last section (trusted-proxy list for the peer bucket, or operator-configurable limits) need a choice before a slice is worth writing.

  3. added
    agent-working
    on Dec 3, 2026
  4. Birfy commented on Dec 3, 2026

    @Birfy
    CollaboratorAuthor

    Taking option A (fix the bucket key), not B: the defect is that the edge collapses every client into one bucket, and that is fixable without turning the limits into configuration.

    Branch dev/3502-auth-peer-limit-behind-edge from main c7c27e22, PR #3504, head 1e4434ad920ef6e274ae0aea327c4987bb5a1004, tree dfd056df. The two option paragraphs in this issue stay as context for B if we ever want it.

  5. Birfy commented on Dec 3, 2026

    @Birfy
    CollaboratorAuthor

    Merged through the queue: PR #3504, head 1e4434ad920ef6e274ae0aea327c4987bb5a1004, squash bf3965559fddc3015f224d7f91ac0913096ad3b2 at 2026-12-03T16:32:29Z, single parent c7c27e22, tree dfd056dfb7c82a5248e500e1401b4b112a2bad82.

    CI at that head was 18/18 success, all completed (head green, not the merge commit). Closing since the fix is in main; option B (configurable limits) is not tracked here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyagent-working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions