diff --git a/CLAUDE.md b/CLAUDE.md index 6bc15da..0de0316 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -62,7 +62,7 @@ Dockerized multi-service personal website self-hosted on a Raspberry Pi. **Job tracker** (`jobs` service, `/jobs/`): the job application tracker, leads inbox, email pipeline and capture userscript now live in their own repo (`adamf/job-tracker` on Gitea) and run here as a published image, with their own Postgres database and role. It has no login: it asks the backend's `/auth/validate-admin` with the visitor's cookies. Nothing of it is left in `backend/`, `python/` or `vue/`; nginx redirects the old `/cv/jobs`, `/cv/leads` and userscript URLs to `/jobs/`. A push to that repo's `main` publishes the image and rolls this stack's `jobs` container onto it; pin `JOBS_IMAGE_TAG` in `.env` to hold a version. Its variables are in `env_registry.json` with `services: ["jobs"]`. -**Nginx** (`nginx/`): Reverse proxy + SPA server. Config is templated (`nginx.conf.template`) and selected at runtime by `entrypoint.sh` based on `DEV_MODE` and certificate presence. Rate limiting on login (5/min), API (30/sec), uploads (5/min). Proxied routes are written once, in `nginx/nginx_routes.conf.template`, which both the production and dev configs include — add a new route there. Production-only pieces (TLS, static asset caching, the GraphQL rate-limit zone, security headers) stay in `nginx.conf.template`; a new rate-limit zone must be declared in both `http` blocks. +**Nginx** (`nginx/`): Reverse proxy + SPA server. Config is templated (`nginx.conf.template`) and selected at runtime by `entrypoint.sh` based on `DEV_MODE` and certificate presence. Rate limiting on login (5/min), API (30/sec), uploads (30/min, burst 20). Proxied routes are written once, in `nginx/nginx_routes.conf.template`, which both the production and dev configs include — add a new route there. Production-only pieces (TLS, static asset caching, the GraphQL rate-limit zone, security headers) stay in `nginx.conf.template`; a new rate-limit zone must be declared in both `http` blocks. ## Backend Structure diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index ca3c10c..e46b84a 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -333,7 +333,7 @@ rate"*. Anything beyond the burst gets an immediate **503**. | `login` | 5/min | 3 | `/api/auth/login` | Brute-force defence. A human mistyping gets 3 tries then one per 12s; a credential-stuffing script gets nothing useful. | | `api` | 30/sec | 20 | `/api/`, `/py/` | Generous on purpose — one SPA page load fans out to several calls. An abuse ceiling, not a quota. | | `graphql` | 10/sec | 10 | `/api/graphql` | Tighter than REST because one query can be arbitrarily expensive. **Production config only**; dev folds GraphQL into `api`. | -| `upload` | 5/min | 3 | `/api/messages/upload` | Uploads can be 50MB and hit disk; bounds how fast one IP fills the volume. | +| `upload` | 30/min | 20 | `/api/messages/upload` | Uploads hit disk; bounds how fast one IP fills the volume. Generous because uploaders must be signed in (accounts are admin-created) and a batch of pictures dropped on a canvas page uploads at once. | | `hotel_search` | 3/min | 2 | `/py/hotels/(search\|scan)` | Each request holds an upstream call for minutes and the Python side has one search slot — concurrency protection more than abuse protection. | The WebSocket endpoint is deliberately unlimited: a socket is one long-lived diff --git a/README.md b/README.md index 8434da8..e000871 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Access tokens are valid for 7 days; refresh tokens for 365 days. `ValidateAdmin` **Protected (auth required)** | Method | Path | Description | | --- | --- | --- | -| POST | `/api/messages/upload` | Upload message file (rate limited: 5/min) | +| POST | `/api/messages/upload` | Upload a file for a chat message or a canvas box (rate limited: 30/min, burst 20) | **Admin (auth + admin required)** | Method | Path | Description | diff --git a/nginx/nginx.conf.template b/nginx/nginx.conf.template index fa5a640..355fb05 100644 --- a/nginx/nginx.conf.template +++ b/nginx/nginx.conf.template @@ -89,8 +89,12 @@ http { # (Production only; the dev template omits it. # Its location is at the bottom of this file, # not in the shared route table.) - # upload 5r/m burst=3 - uploads are 50MB-capable and hit disk; this - # bounds how fast one IP can fill the volume. + # upload 30r/m burst=20 - uploads hit disk; this bounds how fast one IP + # can fill the volume. Generous because only a + # signed-in user can upload and accounts are + # admin-created, and because dropping a batch of + # pictures onto a canvas page uploads them all + # at once — the burst lets ~20 through together. # hotel_search 3r/m burst=2 - each request holds an upstream call to # Travelodge/TfL for up to a few minutes and the # Python side has a single search slot, so this is @@ -109,7 +113,7 @@ http { limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m; limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s; limit_req_zone $binary_remote_addr zone=graphql:10m rate=10r/s; - limit_req_zone $binary_remote_addr zone=upload:10m rate=5r/m; + limit_req_zone $binary_remote_addr zone=upload:10m rate=30r/m; limit_req_zone $binary_remote_addr zone=hotel_search:10m rate=3r/m; log_format compact diff --git a/nginx/nginx_dev.conf.template b/nginx/nginx_dev.conf.template index f670437..9084c8c 100644 --- a/nginx/nginx_dev.conf.template +++ b/nginx/nginx_dev.conf.template @@ -54,7 +54,7 @@ http { # kept equal to production so a limit that would bite there bites here too. limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m; limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s; - limit_req_zone $binary_remote_addr zone=upload:10m rate=5r/m; + limit_req_zone $binary_remote_addr zone=upload:10m rate=30r/m; limit_req_zone $binary_remote_addr zone=hotel_search:10m rate=3r/m; log_format compact diff --git a/nginx/nginx_routes.conf.template b/nginx/nginx_routes.conf.template index 1954038..63e1e08 100644 --- a/nginx/nginx_routes.conf.template +++ b/nginx/nginx_routes.conf.template @@ -148,7 +148,7 @@ } location $BACKEND_ENDPOINT/messages/upload { - limit_req zone=upload burst=3 nodelay; + limit_req zone=upload burst=20 nodelay; rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break; proxy_pass $upstream_backend; proxy_set_header Host $host;