Release v1.2.9: Aktivitaetslog im Admin-Dashboard, Demo wieder online
Wer sich anmeldet, wer es vergeblich versucht und was ein Admin aendert, stand bisher nirgends — der Server hat schlicht nichts protokolliert. Aktivitaetslog: - ./data/audit.log, eine JSON-Zeile pro Event, angehaengt statt neu geschrieben. Bewusst NICHT in db.json: die Datei wird bei jedem Save komplett neu geschrieben, und der Login-Handshake ist unauthentifiziert — ein Log darin haette aus einem Muell-Request einen vollen Rewrite gemacht. - Aufbewahrung ist eine Obergrenze, kein Archiv: AUDIT_MAX (5000) bzw. AUDIT_DAYS (90). - Per Default an (AUDIT_LOG=0 schaltet es ganz ab). IP-Adressen per Default AUS; AUDIT_IP=net speichert nur das Netz, full die ganze Adresse. Nie der User-Agent, nie die Passkey-ID eines Fehlversuchs, nie ein abgelehnter Invite-Code. - Adresse kommt aus CF-Connecting-IP, dann X-Forwarded-For, dann X-Real-IP — ein Cloudflare-Tunnel schreibt den Besucher NICHT in XFF, dort steht sonst nur der Tunnel selbst und sieht dabei voellig plausibel aus. - Loeschen wird selbst protokolliert, die Event-IDs zaehlen weiter: die Luecke bleibt sichtbar. - Neue Karte in views/Admin.jsx (Filter, "Show more"), Aufbereitung in lib/audit.js mit 20 Tests. GET /api/admin/audit und POST /api/admin/audit/clear, beide hinter requireAdmin. Demo: - Die Live-Demo laeuft wieder, jetzt auf der Projektseite selbst statt auf GitHub Pages: opengym.duarte-santos.ch/demo/. Das eingebettete Telefon auf der Startseite geht damit auch wieder — es muss derselbe Host sein, X-Frame-Options ist SAMEORIGIN. Doku: README-Config-Tabelle, .env.example, SELF_HOSTING, SECURITY (inkl. der api/server.js-Zeilenverweise, die wieder stimmen).
This commit is contained in:
1 parent
e709f152c8
commit
8b99a644ed
17 files changed
+658
-67
No files matched your search
+41
-18
@@ -79,65 +79,88 @@ Read this before hosting openGym for anyone other than yourself.
|
||||
- **Passkeys only.** No passwords, no email addresses, no reset flow. Registration and login are
|
||||
verified server-side by `@simplewebauthn/server` against `expectedOrigin: ORIGIN` and
|
||||
`expectedRPID: RP_ID`, and the authenticator's signature counter is stored and updated on every
|
||||
login (`api/server.js:292-318`, `api/server.js:338-358`).
|
||||
login (`api/server.js:382-432`, `api/server.js:443-492`).
|
||||
- **Sessions are a signed cookie.** `gymsid` carries `<uid>:<expiry>:<version>` plus an
|
||||
HMAC-SHA256 tag over it, compared in constant time (`api/server.js:148-161`). The key is 32
|
||||
HMAC-SHA256 tag over it, compared in constant time (`api/server.js:153-166`). The key is 32
|
||||
random bytes generated on first run and written to `./data/secret` with mode `0600`
|
||||
(`api/server.js:34-36`). The cookie is `HttpOnly` and `SameSite=Lax`, and gets `Secure` **only
|
||||
when `ORIGIN` starts with `https:`** (`api/server.js:29`, `api/server.js:198-201`).
|
||||
(`api/server.js:39-41`). The cookie is `HttpOnly` and `SameSite=Lax`, and gets `Secure` **only
|
||||
when `ORIGIN` starts with `https:`** (`api/server.js:34`, `api/server.js:205-208`).
|
||||
- **Any user can end every session they have.** `POST /api/logout/all` increments that account's
|
||||
session version, and every authenticated request checks the version in the cookie against the
|
||||
one on the user record (`api/server.js:167`, `api/server.js:187-188`), so every cookie ever
|
||||
one on the user record (`api/server.js:172`, `api/server.js:192-193`), so every cookie ever
|
||||
issued for the account — on every device, including a copy someone walked off with — stops
|
||||
verifying at once. Passkeys are untouched; signing back in works immediately.
|
||||
- **Data is isolated per user by the session's uid.** `GET`/`PUT /api/data` only ever touch
|
||||
`state-<uid>.json` for the caller (`api/server.js:375-392`); no route lets a normal user name
|
||||
`state-<uid>.json` for the caller (`api/server.js:517-534`); no route lets a normal user name
|
||||
another user.
|
||||
- **Disabling an account takes effect immediately.** Every authenticated request and every login
|
||||
is rejected for a disabled user (`api/server.js:184`, `api/server.js:357`).
|
||||
is rejected for a disabled user (`api/server.js:189`, `api/server.js:488`).
|
||||
- **There is an activity log.** Sign-ins, sign-outs, failed and refused attempts, and every admin
|
||||
action are appended to `./data/audit.log`, one JSON object per line, and shown in the admin
|
||||
dashboard. It is on by default (`AUDIT_LOG=0` disables it) and capped at `AUDIT_MAX` events /
|
||||
`AUDIT_DAYS` days. Clearing it from the dashboard is itself recorded and the event ids keep
|
||||
counting, so an erased stretch always leaves a visible gap.
|
||||
|
||||
### What it does not do
|
||||
|
||||
- **Nothing in `./data` is encrypted.** It holds `db.json` (users, passkey public keys, push
|
||||
subscriptions, invite codes), one `state-<uid>.json` per user with their complete workout
|
||||
history and body-weight log, `secret`, and `vapid.json`. Anyone who can read that folder — you,
|
||||
history and body-weight log, `audit.log`, `secret`, and `vapid.json`. Anyone who can read that folder — you,
|
||||
whoever holds the backups, whoever gets into the host — can read every user's data, and with
|
||||
`secret` can mint a valid session cookie for any account. **If you host openGym for other
|
||||
people, they are trusting you exactly as much as they'd trust any server operator.**
|
||||
people, they are trusting you exactly as much as they'd trust any server operator.** With the
|
||||
activity log on, `./data/audit.log` adds everyone's sign-in times to that — worth remembering
|
||||
before an archive of `./data` goes somewhere you don't run.
|
||||
- **Admins can read everything.** A user listed in `ADMIN_UIDS` (or flagged `admin: true` in
|
||||
`db.json`) gets every user's full history and body weight, can disable accounts, and can create
|
||||
or revoke invite codes (`api/server.js:460-540`). Off by default — a fresh instance has no admin.
|
||||
or revoke invite codes (`api/server.js:600-722`). Off by default — a fresh instance has no admin.
|
||||
- **Sessions can't be revoked one device at a time.** Revocation is per *account*, not per
|
||||
session: `POST /api/logout/all` kills all of them at once and there is no device list to pick
|
||||
from. `POST /api/logout` on its own only clears the cookie in that one browser
|
||||
(`api/server.js:361`) — a copy taken beforehand keeps working. Sessions last **90 days** by
|
||||
default, settable with `SESSION_DAYS` (`api/server.js:26`); each cookie carries the lifetime it
|
||||
(`api/server.js:498-502`) — a copy taken beforehand keeps working. Sessions last **90 days** by
|
||||
default, settable with `SESSION_DAYS` (`api/server.js:31`); each cookie carries the lifetime it
|
||||
was issued with, so changing the setting doesn't reach cookies that are already out. Deleting
|
||||
`./data/secret` and restarting still works as the instance-wide reset, and disabling an account
|
||||
still locks out one user completely.
|
||||
- **CSRF protection is `SameSite=Lax` and nothing else.** There are no CSRF tokens.
|
||||
- **User verification is preferred, not required.** Both handshakes pass
|
||||
`requireUserVerification: false` (`api/server.js:297`, `api/server.js:343`), so a passkey
|
||||
`requireUserVerification: false` (`api/server.js:396`, `api/server.js:465`), so a passkey
|
||||
released without a biometric or PIN is still accepted. In practice: unlocked device ≈ account
|
||||
access.
|
||||
- **One passkey per profile, and no recovery.** Every successful registration creates a *new*
|
||||
profile (`api/server.js:309-319`); there is no route to attach a second passkey to an existing
|
||||
profile (`api/server.js:421-430`); there is no route to attach a second passkey to an existing
|
||||
one, and no email or reset path. Lose the passkey and that profile is unreachable — only direct
|
||||
surgery on `./data` gets it back.
|
||||
- **Disabling someone isn't a ban.** They can still register a fresh profile with a new passkey
|
||||
unless `INVITE_ONLY=1` is set.
|
||||
unless `INVITE_ONLY=1` is set. It also makes them near-invisible in the activity log: a disabled
|
||||
account is refused at the session check, so nothing it does produces an entry except the failed
|
||||
sign-ins it keeps attempting.
|
||||
- **HTTPS is required and the app doesn't provide it.** The API container speaks plain HTTP and
|
||||
nginx listens on `:80` (`web/nginx.conf`); TLS is your reverse proxy's job. Without it,
|
||||
browsers won't do passkeys at all (except on `http://localhost`) and the session cookie is sent
|
||||
in the clear.
|
||||
- **No rate limiting anywhere.** Nothing throttles logins, registrations or writes, and
|
||||
`POST /api/register/options` still answers whether an invite code is valid
|
||||
(`api/server.js:272`), so an invite-only instance on the open internet should have a rate limit
|
||||
in front of it. New invite codes are 16 hex characters — 64 bits (`api/server.js:525`) — which
|
||||
(`api/server.js:360`), so an invite-only instance on the open internet should have a rate limit
|
||||
in front of it. New invite codes are 16 hex characters — 64 bits (`api/server.js:668`) — which
|
||||
makes guessing one impractical even unthrottled; codes generated by earlier versions are 8
|
||||
characters / 32 bits and still work, so revoke and reissue any that are still unused. The only
|
||||
hard limit
|
||||
in the app is a 5 MB request body (`api/server.js:27`).
|
||||
in the app is a 5 MB request body (`api/server.js:32`).
|
||||
- **The activity log is not an audit archive, and it records less than you might assume.** No IP
|
||||
address unless you set `AUDIT_IP` (`net` truncates to a /24 or /48; the default is `off`, and
|
||||
when it is on the address is taken from `CF-Connecting-IP`, `X-Forwarded-For` or `X-Real-IP` and
|
||||
is therefore only as trustworthy as the proxy in front of you), never
|
||||
the browser's user-agent, and never the passkey id behind a failed sign-in — that id is a stable
|
||||
handle for one device, and storing it would let an admin follow an unknown device from attempt
|
||||
to attempt. So a failed sign-in from a passkey this instance doesn't know is recorded as a time
|
||||
and nothing else. Retention is a cap, not an archive: old events are dropped, not exported. Any
|
||||
admin can clear the whole log from the dashboard. And four of the paths that write to it —
|
||||
the invite check on `POST /api/register/options`, and the expired-challenge and unknown-passkey
|
||||
branches of the register/login handshakes — are reachable **without a session**, so with no rate
|
||||
limit in front (see below) anyone can fill the log with noise. It is an append of ~110 bytes per
|
||||
event to a capped file, never a rewrite of `db.json`, so the cost is a log full of noise rather
|
||||
than a full disk or a slow server.
|
||||
- **A few endpoints answer without a session:** `/api/health` (which includes the total user
|
||||
count), `/api/config` (whether invite-only is on), `/api/push/public-key`, and the
|
||||
register/login handshakes.
|
||||
|
||||
Reference in new issue
Block a user