Spaces:
Sleeping
Sleeping
Commit ·
d0c44b2
1
Parent(s): e830ad4
fix(deploy): trust x-forwarded-for for per-IP rate limiting
Browse filesHF Spaces sits behind one proxy layer, so adapter-node's default client address is
the proxy's, which collapsed the per-IP login limiter into a single global bucket.
Bake ADDRESS_HEADER=x-forwarded-for and XFF_DEPTH=1 into the runtime image, and
raise the limiter to 30/min so users behind a shared NAT are not locked out.
- Dockerfile +3 -1
- README.md +2 -0
- src/lib/server/app.ts +1 -1
Dockerfile
CHANGED
|
@@ -11,7 +11,9 @@ ENV NODE_ENV=production \
|
|
| 11 |
PORT=7860 \
|
| 12 |
HOST=0.0.0.0 \
|
| 13 |
STORAGE=hf \
|
| 14 |
-
BODY_SIZE_LIMIT=8M
|
|
|
|
|
|
|
| 15 |
COPY --from=build /app/build ./build
|
| 16 |
COPY --from=build /app/node_modules ./node_modules
|
| 17 |
COPY --from=build /app/package.json ./package.json
|
|
|
|
| 11 |
PORT=7860 \
|
| 12 |
HOST=0.0.0.0 \
|
| 13 |
STORAGE=hf \
|
| 14 |
+
BODY_SIZE_LIMIT=8M \
|
| 15 |
+
ADDRESS_HEADER=x-forwarded-for \
|
| 16 |
+
XFF_DEPTH=1
|
| 17 |
COPY --from=build /app/build ./build
|
| 18 |
COPY --from=build /app/node_modules ./node_modules
|
| 19 |
COPY --from=build /app/package.json ./package.json
|
README.md
CHANGED
|
@@ -32,6 +32,8 @@ Set these in the Space **Settings → Variables and secrets**:
|
|
| 32 |
| `COMPACTION_INTERVAL_MS` | variable | default `3600000` (1 hour) |
|
| 33 |
|
| 34 |
`BODY_SIZE_LIMIT=8M`, `STORAGE=hf`, `PORT`, `HOST` and `NODE_ENV` are baked into the Dockerfile; there is no need to set them in the Space.
|
|
|
|
|
|
|
| 35 |
|
| 36 |
First boot creates the `admin` user with password `1234`; the first admin login forces a password change.
|
| 37 |
Then create your friends' accounts on `/admin`.
|
|
|
|
| 32 |
| `COMPACTION_INTERVAL_MS` | variable | default `3600000` (1 hour) |
|
| 33 |
|
| 34 |
`BODY_SIZE_LIMIT=8M`, `STORAGE=hf`, `PORT`, `HOST` and `NODE_ENV` are baked into the Dockerfile; there is no need to set them in the Space.
|
| 35 |
+
`ADDRESS_HEADER=x-forwarded-for` and `XFF_DEPTH=1` are baked in too, so the per-IP login rate limiter
|
| 36 |
+
sees the real client address through the Spaces proxy rather than the proxy's own.
|
| 37 |
|
| 38 |
First boot creates the `admin` user with password `1234`; the first admin login forces a password change.
|
| 39 |
Then create your friends' accounts on `/admin`.
|
src/lib/server/app.ts
CHANGED
|
@@ -92,7 +92,7 @@ async function build(): Promise<App> {
|
|
| 92 |
ledger,
|
| 93 |
guard,
|
| 94 |
loginLimiter: new RateLimiter(5, 60_000),
|
| 95 |
-
ipLimiter: new RateLimiter(
|
| 96 |
compaction,
|
| 97 |
syncReadOnly() {
|
| 98 |
const readOnly = !guard.canWrite;
|
|
|
|
| 92 |
ledger,
|
| 93 |
guard,
|
| 94 |
loginLimiter: new RateLimiter(5, 60_000),
|
| 95 |
+
ipLimiter: new RateLimiter(30, 60_000),
|
| 96 |
compaction,
|
| 97 |
syncReadOnly() {
|
| 98 |
const readOnly = !guard.canWrite;
|