mirror of
https://github.com/Such-Software/xmrcheckout.git
synced 2026-12-01 12:14:11 +01:00
fix(nginx): refuse the admin API at the public edge
nginx proxied all of /api/ to the internet, including /api/admin, which returns every merchant's API key and webhook secret behind a single shared key. The only caller is the admin panel's server actions, so nginx now answers /api/admin with a 404 and those actions reach the API directly over the compose network through ADMIN_API_BASE_URL (default http://api:8000), falling back to API_BASE_URL for non-Docker installs.
This commit is contained in:
@@ -46,4 +46,6 @@ CONTACT_EMAIL=sales@such.software
|
||||
|
||||
# UI
|
||||
API_BASE_URL=http://api:8000
|
||||
# Private API address for the admin panel; nginx refuses /api/admin publicly.
|
||||
ADMIN_API_BASE_URL=http://api:8000
|
||||
SITE_URL=https://example.com
|
||||
|
||||
@@ -256,6 +256,9 @@ Start from `.env.example` and adjust for your host. For non-Docker deployments y
|
||||
- `API_BASE_URL` for the UI:
|
||||
- If using a reverse proxy that routes `/api/` to the API on the same origin, set `API_BASE_URL=https://example.com`
|
||||
- If not using a reverse proxy, set `API_BASE_URL=http://127.0.0.1:8000` (see the notes in step 6)
|
||||
- `ADMIN_API_BASE_URL` for the UI's admin panel, set to the API's private address
|
||||
(for example `http://127.0.0.1:8000`). It falls back to `API_BASE_URL`; keep `/api/admin`
|
||||
off your public reverse proxy.
|
||||
|
||||
If you need a new `API_KEY_ENCRYPTION_KEY` value:
|
||||
|
||||
@@ -375,6 +378,18 @@ From the admin panel you can:
|
||||
|
||||
All endpoints require the `X-Admin-Key` header set to your `ADMIN_API_KEY`.
|
||||
|
||||
These endpoints return merchant API keys and webhook secrets, so the bundled nginx
|
||||
refuses `/api/admin` with a 404. The admin panel calls them from the UI server over
|
||||
the compose network (`ADMIN_API_BASE_URL`, default `http://api:8000`). To call them
|
||||
yourself, do it from inside that network. This example reads the key from the API
|
||||
container's environment, so it never appears on a command line:
|
||||
|
||||
```
|
||||
docker compose exec api python -c 'import os, urllib.request as u; print(u.urlopen(u.Request("http://127.0.0.1:8000/api/admin/users", headers={"X-Admin-Key": os.environ["ADMIN_API_KEY"]})).read().decode())'
|
||||
```
|
||||
|
||||
If you run your own reverse proxy, refuse `/api/admin` there as well.
|
||||
|
||||
```
|
||||
POST /api/admin/auth/verify — verify admin key
|
||||
GET /api/admin/users — list all merchants
|
||||
|
||||
@@ -193,6 +193,7 @@ services:
|
||||
NEXT_PUBLIC_SITE_NAME: ${SITE_NAME:-XMR Checkout}
|
||||
environment:
|
||||
API_BASE_URL: ${API_BASE_URL:-http://nginx}
|
||||
ADMIN_API_BASE_URL: ${ADMIN_API_BASE_URL:-http://api:8000}
|
||||
NEXT_PUBLIC_SITE_URL: ${SITE_URL:-http://localhost}
|
||||
NEXT_PUBLIC_DONATIONS_ENABLED: ${DONATIONS_ENABLED:-false}
|
||||
NEXT_PUBLIC_TURNSTILE_SITE_KEY: ${TURNSTILE_SITE_KEY:-}
|
||||
|
||||
@@ -26,6 +26,15 @@ server {
|
||||
return 308 $scheme://$host$uri$is_args$args;
|
||||
}
|
||||
|
||||
# The admin API returns every merchant's API key and webhook secret. Only the
|
||||
# UI's server actions call it, over the compose network (ADMIN_API_BASE_URL),
|
||||
# so the public edge refuses it. ^~ keeps any later regex location from
|
||||
# claiming these paths, and nginx matches the normalized URI, so encoded or
|
||||
# dot-segment spellings land here too.
|
||||
location ^~ /api/admin {
|
||||
return 404;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
set $api_upstream "api";
|
||||
# No URI suffix: nginx preserves the complete /api/v1/... request path.
|
||||
|
||||
@@ -4,7 +4,10 @@ import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
const apiBaseUrl = process.env.API_BASE_URL ?? "http://localhost:8000";
|
||||
// The public nginx edge refuses /api/admin, so admin calls go straight to the
|
||||
// API service. Compose sets ADMIN_API_BASE_URL to http://api:8000.
|
||||
const apiBaseUrl =
|
||||
process.env.ADMIN_API_BASE_URL ?? process.env.API_BASE_URL ?? "http://localhost:8000";
|
||||
|
||||
const ADMIN_COOKIE = "xmrcheckout_admin_key";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user