Count per-address limits on the hop a trusted proxy added; limit signup

The limits read the leftmost X-Forwarded-For entry, which the client writes,
and the LAN nginx appended to it. The address now comes from uvicorn's
proxy-headers middleware (rightmost hop not in FORWARDED_ALLOW_IPS), applied
in the app too so tunnel-replayed calls resolve the same way; nginx sets the
header to $remote_addr and the compose backend trusts the Docker networks.
/users/signup gets a per-address limit of 10 an hour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013GAeg4Jo6xjZzjwy9QDWMQ
This commit is contained in:
2026-10-06 12:15:58 +02:00
co-authored by Claude Opus 5.5
parent 7f06260c1a
commit 8cfe5c4e6e
10 changed files with 82 additions and 19 deletions
+9
View File
@@ -16,6 +16,7 @@ from fastapi.responses import JSONResponse
from fastapi.routing import APIRoute
from fluksio_worker.worker_main import ARTIFACT_DIR_ENV, ARTIFACT_VOLATILE_DIR_ENV
from starlette.middleware.cors import CORSMiddleware
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
from fluksio import __version__
from fluksio.api.main import api_router
@@ -433,6 +434,14 @@ if settings.all_cors_origins:
allow_headers=["*"],
)
# The caller's address, for every per-address limit: the rightmost
# X-Forwarded-For hop that is not a trusted proxy. uvicorn does this for what
# it serves, but a call the portal tunnel replays arrives over an in-process
# transport as 127.0.0.1 and never passes through it. Doing it again here
# covers that, with uvicorn's own semantics, and is a no-op on a request
# uvicorn already resolved. Added last, so it is the outermost layer.
app.add_middleware(ProxyHeadersMiddleware, trusted_hosts=settings.FORWARDED_ALLOW_IPS)
app.include_router(api_router, prefix=settings.API_V1_STR)