From 8962e4655de7537faafd405361c6ada1d5ed21a8 Mon Sep 17 00:00:00 2001 From: jlcjak <206324213+jlcjak@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:58:35 +0200 Subject: [PATCH] order: password-protect the /admin order list in nginx The order list was reachable by anyone holding the admin token in a ?k= URL, which is easy to paste into chat or browser history. nginx now asks for a password first (user admin, a bcrypt hash in /etc/nginx/fab-admin.htpasswd) and hands the app its token itself from a root-only include (/etc/fab/nginx-admin.conf), so the person signs in with a password alone. /admin gets its own rate limit (30/min per address, burst 20) so guesses are slow. Without the password file every /admin request fails closed; without the token include the app asks for ?k= as before. Tested on the live server: no, wrong or token-only credentials get 401 (also for /admin/files, POST /admin/order, /%61dmin, //admin, /x/../admin); the right password lists the orders; /v1/health and /terms unchanged; rapid wrong guesses are cut off with 503. Co-Authored-By: Claude Opus 5.5 --- order/README.md | 6 ++++-- order/deploy/nginx.conf | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/order/README.md b/order/README.md index e3067725d1..30a184a04f 100644 --- a/order/README.md +++ b/order/README.md @@ -21,8 +21,10 @@ A small Python service behind nginx on a Debian host. Checkout (an open one is reused) that collects card, email, phone and the shipping address in the quote's country, and shows the price-may-change terms beside Pay. There is no quote page: the quote is only shown in Backplane. Stripe comes back to `/q/{id}/done` or `/q/{id}/cancelled`, one line each. -- `/admin`: paid orders, to place by hand. Takes `?k=$FAB_ADMIN_TOKEN` once, which then - becomes a cookie. +- `/admin`: paid orders, to place by hand. nginx asks for a password first (user `admin`, a bcrypt + line in `/etc/nginx/fab-admin.htpasswd`, made with `mkpasswd -m bcrypt`) and then hands the app its + token from `/etc/fab/nginx-admin.conf`; without that file the page takes `?k=$FAB_ADMIN_TOKEN` once, + which then becomes a cookie. The person sees three lines and a total, four for the US: - manufacturing; diff --git a/order/deploy/nginx.conf b/order/deploy/nginx.conf index 48f53be37e..85347b1cf0 100644 --- a/order/deploy/nginx.conf +++ b/order/deploy/nginx.conf @@ -3,6 +3,7 @@ limit_req_zone $binary_remote_addr zone=fab_api:10m rate=5r/s; limit_req_zone $binary_remote_addr zone=fab_up:10m rate=6r/m; limit_conn_zone $binary_remote_addr zone=fab_conn:10m; +limit_req_zone $binary_remote_addr zone=fab_admin:10m rate=30r/m; # no query strings in the log: they can carry a quote's token log_format fab '$remote_addr [$time_local] "$request_method $uri" $status $body_bytes_sent $request_time'; @@ -45,6 +46,22 @@ server { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto https; } + # The order list: a password (user admin; bcrypt hash in /etc/nginx/fab-admin.htpasswd, readable by + # www-data) and then the app's own admin token, which nginx adds from /etc/fab/nginx-admin*.conf + # (root only; one line: proxy_set_header Cookie "fab_admin=";). With no password + # file every /admin request fails; with no token file the page asks for ?k= as before. + location ^~ /admin { + limit_req zone=fab_admin burst=20 nodelay; + auth_basic "Backplane orders"; + auth_basic_user_file /etc/nginx/fab-admin.htpasswd; + client_max_body_size 256k; + proxy_pass http://127.0.0.1:8090; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto https; + include /etc/fab/nginx-admin*.conf; + } location / { limit_req zone=fab_api burst=40 nodelay; client_max_body_size 256k;